943,696 Members | Top Members by Rank

Ad:
  • Assembly Discussion Thread
  • Unsolved
  • Views: 3720
  • Assembly RSS
Feb 7th, 2009
0

Win32 NASM compile probs with nasmw + lcclnk

Expand Post »
I'm trying to compile an example nasm program I downloaded for windows. But I can't get it to compile.

Assembly Syntax (Toggle Plain Text)
  1. C:\nasm-2.06rc1\nasmw -f win32 example.asm
  2. C:\lcc\bin\lcclnk -s -subsystem windows example.obj

When I compile it with that, the first part of it goes fine, it's when I use lcclnk to link it I get these error messages:

Assembly Syntax (Toggle Plain Text)
  1. C:\Documents and Settings\Administrator\Desktop\NASM\DEMO>C:\lcc\bin\lcclnk -s -
  2. subsystem windows example.obj
  3. example.obj .text: undefined reference to 'LoadIconA'
  4. example.obj .text: undefined reference to 'LoadCursorA'
  5. example.obj .text: undefined reference to 'RegisterClassA'
  6. example.obj .text: undefined reference to 'GetLastError'
  7. example.obj .text: undefined reference to 'CreateWindowExA'
  8. example.obj .text: undefined reference to 'ShowWindow'
  9. example.obj .text: undefined reference to 'UpdateWindow'
  10. example.obj .text: undefined reference to 'GetMessageA'
  11. example.obj .text: undefined reference to 'TranslateMessage'
  12. example.obj .text: undefined reference to 'DispatchMessageA'
  13. example.obj .text: undefined reference to 'ExitProcess'
  14. example.obj .text: undefined reference to 'DefWindowProcA'
  15. example.obj .text: undefined reference to 'PostQuitMessage'
  16. example.obj .text: undefined reference to 'BeginPaint'
  17. example.obj .text: undefined reference to 'DrawTextA'
  18. example.obj .text: undefined reference to 'EndPaint'

Here's the first part of my code:

Assembly Syntax (Toggle Plain Text)
  1. %include "C:\Documents and Settings\Administrator\Desktop\NASM\DEMO\win32n.inc"
  2.  
  3. extern RegisterClassA
  4. extern CreateWindowExA
  5. extern CreateWindow
  6. extern ShowWindow
  7. extern UpdateWindow
  8. extern GetMessageA
  9. extern TranslateMessage
  10. extern DispatchMessageA
  11. extern DefWindowProcA
  12. extern ExitProcess
  13. extern MessageBeep
  14. extern GetLastError
  15. extern LoadIconA
  16. extern LoadCursorA
  17. extern PostQuitMessage
  18.  
  19. extern BeginPaint
  20. extern EndPaint
  21. extern DrawTextA
  22.  
  23. global _WinMain@16
  24.  
  25. SEGMENT .text USE32 class=code
  26. _WinMain@16:
  27.  
  28. %define ebp_hInstance ebp+8 ; handle of current instance
  29. %define ebp_hPrevInstance ebp+0ch ; handle of previous instance
  30. %define ebp_lpszCmdLine ebp+10h ; pointer to command line
  31. %define ebp_nCmdShow ebp+14h ; show state of window


I'm determined to get this working, as I really want to start coding in NASM for windows.

Thanks in advance.
Reputation Points: 10
Solved Threads: 0
Newbie Poster
int_80 is offline Offline
5 posts
since Feb 2009
Feb 7th, 2009
0

Re: Win32 NASM compile probs with nasmw + lcclnk

Does the link know where and to include C headers etc....

Just link it with gcc using gcc example.obj -o example.exe
Reputation Points: 325
Solved Threads: 118
Master Poster
Freaky_Chris is offline Offline
702 posts
since Apr 2008
Feb 7th, 2009
0

Re: Win32 NASM compile probs with nasmw + lcclnk

Does the link know where and to include C headers etc....

Just link it with gcc using gcc example.obj -o example.exe
"Does the link know where and to include C headers etc...." Good point, how does one go about doing that? I tried linking it with gcc, but I still get the same error message.
Reputation Points: 10
Solved Threads: 0
Newbie Poster
int_80 is offline Offline
5 posts
since Feb 2009
Feb 7th, 2009
0

Re: Win32 NASM compile probs with nasmw + lcclnk

I'd recommend a read of Narue's tutorial, its a few posts down and is a brillaint intro to NASM on windows
Reputation Points: 325
Solved Threads: 118
Master Poster
Freaky_Chris is offline Offline
702 posts
since Apr 2008
Feb 8th, 2009
0

Re: Win32 NASM compile probs with nasmw + lcclnk

I'd recommend a read of Narue's tutorial, its a few posts down and is a brillaint intro to NASM on windows
I get it now. It doesn't know where to get the winAPI functions from.

I added this:
Assembly Syntax (Toggle Plain Text)
  1. import MessageBoxA user32.dll

Still though, it's still pissing me about. There's so many annoying little things that don't work, yet should.

Assembly Syntax (Toggle Plain Text)
  1. [extern MessageBoxA]
  2. import MessageBoxA user32.dll
  3.  
  4. [global _main]
  5. [segment .text]
  6.  
  7.  
  8. _main:
  9. push dword szText ; Push param onto stack
  10. call box ; Call our function
  11. add esp, 4 ; un-bork the stack?
  12. ret
  13.  
  14. box:
  15. enter 0,0
  16. mov eax, [ebp+8] ; Pull first param off stack
  17. push dword 0 ; MB_OK style
  18. push dword eax ; First Param
  19. push dword eax ; First Param
  20. push dword 0 ; HWND parent (NULL)
  21. call MessageBoxA
  22.  
  23. xor eax, eax
  24. leave
  25. ret
  26.  
  27. [segment .data]
  28. szText: db 'Hello',0

if I link it with alink, I get this (which doesn't work):

Assembly Syntax (Toggle Plain Text)
  1. C:\nasm-2.06rc1>nasm -o messagebox.obj -f obj messagebox.asm
  2.  
  3. C:\nasm-2.06rc1>c:\alink\alink.exe -oPE -subsys con messagebox.obj
  4. ALINK v1.6 (C) Copyright 1998-9 Anthony A.J. Williams.
  5. All Rights Reserved
  6.  
  7. Loading file messagebox.obj
  8. matched Externs
  9. matched ComDefs
  10. Generating PE file messagebox.exe
  11. Warning, no entry point specified
  12. Error writing to file messagebox.exe

If I link it with gcc I get this:

Assembly Syntax (Toggle Plain Text)
  1. C:\nasm-2.06rc1>nasm -o messagebox.obj -f obj messagebox.asm
  2.  
  3. C:\nasm-2.06rc1>c:\MinGW\bin\gcc.exe "C:\nasm-2.06rc1\messagebox.obj" -o size2.e
  4. xe
  5. C:\nasm-2.06rc1\messagebox.obj: file not recognized: File format not recognized
  6. collect2: ld returned 1 exit status

What the hell's going? Is there any documentation online about compiling things in nasm?
Last edited by int_80; Feb 8th, 2009 at 8:35 am.
Reputation Points: 10
Solved Threads: 0
Newbie Poster
int_80 is offline Offline
5 posts
since Feb 2009
Feb 8th, 2009
0

Re: Win32 NASM compile probs with nasmw + lcclnk

ASM Syntax (Toggle Plain Text)
  1. [segment .text]
  2. global _main
  3.  
  4. _main:
Should work with GCC, as for ALINK I think that require .start or ..start as it's entry point.

Chris
Reputation Points: 325
Solved Threads: 118
Master Poster
Freaky_Chris is offline Offline
702 posts
since Apr 2008
Feb 8th, 2009
0

Re: Win32 NASM compile probs with nasmw + lcclnk

You're the man chris!!!

Thanks.
Reputation Points: 10
Solved Threads: 0
Newbie Poster
int_80 is offline Offline
5 posts
since Feb 2009

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in Assembly Forum Timeline: Let's learn assembly!
Next Thread in Assembly Forum Timeline: pause program





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC