Author Topic: can't get a NASM program to link -HELP  (Read 16423 times)

mark allyn

  • Guest
can't get a NASM program to link -HELP
« on: August 12, 2009, 03:26:51 AM »
Hello everyone-

I have a vey simple NASM program that just calls _printf and returns.  The program assembles with NASM. BUT, when I go to link it, the wheels come off.  I get this message back saying that there is an undefiened reference to WinMain@16.  This undefined reference occurs in libmingw32.a.  

I don't understand what in blazes is happening.  I deleted the entire MinGW folder on my hard drive and downloaded an entirely fresh version of MinGW and got the same message.  I rebooted the system from a cold start too.  I am NOT calling WinMain in the program anywhere.  

i simply cannot imagine what is going on.  Am desperate.

Mark Allyn

Offline Frank Kotler

  • NASM Developer
  • Hero Member
  • *****
  • Posts: 2667
  • Country: us
Re: can't get a NASM program to link -HELP
« Reply #1 on: August 12, 2009, 05:05:00 AM »
As a wild guess, I'll guess that WinMain@16 is the default entrypoint that the startup code expects to find. (dunno where 16 comes from, I only count 12...) Try:

%define _main WinMain@16 ; might want an underscore?

global _main
extern _printf

Courage, Mark! :)

Best,
Frank

mark allyn

  • Guest
Re: can't get a NASM program to link -HELP
« Reply #2 on: August 12, 2009, 10:55:55 AM »
Hi Frank -

I tried your wild guess but it didn't work.  Here's the command lines:

c:\MinGW\bin\nasm.exe -f win32 -o testpgm.o  testpgm.asm
c:\MinGW\bin\gcc.exe -o testpgm.exe testpgm.o

Here's the code:

%define _main WinMain@16

segment .data
msg db "hiya", 0
outfmt db "%s", 0

segment .text
   global _test
   extern _printf
_test:
   enter 0,0
   pusha
   push msg
   push outfmt
   call _printf
   add esp, 8
   popa
   mov eax, 0
   leave
   ret

Doesn't matter to the linker whether the define is in or out. It continues to report "undefined reference to WinMain@16.

I wrote a little tiny C program just to see how much I might have destroyed in the MinGW library.  The C program compiled and linked fine and ran as expected....

Thanks for your help.

Mark A.

japheth

  • Guest
Re: can't get a NASM program to link -HELP
« Reply #3 on: August 12, 2009, 04:16:38 PM »
If MinGW gcc is to link a Win32 console application, it needs a public label _main in the object module. So just replace all occurances of _test by _main.

japheth