Win32 NASM compile probs with nasmw + lcclnk

Please support our Assembly advertiser: Programming Forums - DaniWeb Sister Site
Reply

Join Date: Feb 2009
Posts: 5
Reputation: int_80 is an unknown quantity at this point 
Solved Threads: 0
int_80 int_80 is offline Offline
Newbie Poster

Win32 NASM compile probs with nasmw + lcclnk

 
0
  #1
Feb 7th, 2009
I'm trying to compile an example nasm program I downloaded for windows. But I can't get it to compile.

  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:

  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:

  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.
Reply With Quote Quick reply to this message  
Join Date: Apr 2008
Posts: 670
Reputation: Freaky_Chris is a jewel in the rough Freaky_Chris is a jewel in the rough Freaky_Chris is a jewel in the rough 
Solved Threads: 113
Freaky_Chris's Avatar
Freaky_Chris Freaky_Chris is offline Offline
Practically a Master Poster

Re: Win32 NASM compile probs with nasmw + lcclnk

 
0
  #2
Feb 7th, 2009
Does the link know where and to include C headers etc....

Just link it with gcc using gcc example.obj -o example.exe
Knowledge is power -- But experience is everything
Reply With Quote Quick reply to this message  
Join Date: Feb 2009
Posts: 5
Reputation: int_80 is an unknown quantity at this point 
Solved Threads: 0
int_80 int_80 is offline Offline
Newbie Poster

Re: Win32 NASM compile probs with nasmw + lcclnk

 
0
  #3
Feb 7th, 2009
Originally Posted by Freaky_Chris View Post
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.
Reply With Quote Quick reply to this message  
Join Date: Apr 2008
Posts: 670
Reputation: Freaky_Chris is a jewel in the rough Freaky_Chris is a jewel in the rough Freaky_Chris is a jewel in the rough 
Solved Threads: 113
Freaky_Chris's Avatar
Freaky_Chris Freaky_Chris is offline Offline
Practically a Master Poster

Re: Win32 NASM compile probs with nasmw + lcclnk

 
0
  #4
Feb 7th, 2009
I'd recommend a read of Narue's tutorial, its a few posts down and is a brillaint intro to NASM on windows
Knowledge is power -- But experience is everything
Reply With Quote Quick reply to this message  
Join Date: Feb 2009
Posts: 5
Reputation: int_80 is an unknown quantity at this point 
Solved Threads: 0
int_80 int_80 is offline Offline
Newbie Poster

Re: Win32 NASM compile probs with nasmw + lcclnk

 
0
  #5
Feb 8th, 2009
Originally Posted by Freaky_Chris View Post
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:
  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.

  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):

  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:

  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.
Reply With Quote Quick reply to this message  
Join Date: Apr 2008
Posts: 670
Reputation: Freaky_Chris is a jewel in the rough Freaky_Chris is a jewel in the rough Freaky_Chris is a jewel in the rough 
Solved Threads: 113
Freaky_Chris's Avatar
Freaky_Chris Freaky_Chris is offline Offline
Practically a Master Poster

Re: Win32 NASM compile probs with nasmw + lcclnk

 
0
  #6
Feb 8th, 2009
  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
Knowledge is power -- But experience is everything
Reply With Quote Quick reply to this message  
Join Date: Feb 2009
Posts: 5
Reputation: int_80 is an unknown quantity at this point 
Solved Threads: 0
int_80 int_80 is offline Offline
Newbie Poster

Re: Win32 NASM compile probs with nasmw + lcclnk

 
0
  #7
Feb 8th, 2009
You're the man chris!!!

Thanks.
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:



Other Threads in the Assembly Forum
Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC