Author Topic: undefined reference to WinMain@16  (Read 23337 times)

nobody

  • Guest
undefined reference to WinMain@16
« on: February 24, 2007, 06:25:10 PM »
I'm compiling the hello example from a command prompt under Windows XP as follows:

nasm -f win32 -l hello.lst hello.asm
   gcc -o hello hello.obj

However, I get the error "undefined reference to WinMain@16"

Am I missing a nasm setting or a gcc setting?  Should I be using nasmw instead of nasm?

nobody

  • Guest
Re: undefined reference to WinMain@16
« Reply #1 on: February 24, 2007, 09:21:49 PM »
Can you post the source code?

-----
nmt

nobody

  • Guest
Re: undefined reference to WinMain@16
« Reply #2 on: February 24, 2007, 10:48:28 PM »
Here's the source code (borrowed from http://www.csee.umbc.edu/help/nasm/sample.shtml):

;  hello.asm  a first program for nasm for Linux, Intel, gcc
;
; assemble:   nasm -f elf -l hello.lst  hello.asm
; link:      gcc -o hello  hello.o
; run:           hello
; output is:   Hello World

SECTION .data      ; data section
msg:   db "Hello World",10   ; the string to print, 10=cr
len:   equ $-msg      ; "$" means "here"
            ; len is a value, not an address

SECTION .text      ; code section
        global main      ; make label available to linker
main:            ; standard  gcc  entry point

mov   edx,len      ; arg3, length of string to print
   mov   ecx,msg      ; arg2, pointer to string
   mov   ebx,1      ; arg1, where to write, screen
   mov   eax,4      ; write command to int 80 hex
   int   0x80      ; interrupt 80 hex, call kernel

mov   ebx,0      ; exit code, 0=normal
   mov   eax,1      ; exit command to kernel
   int   0x80      ; interrupt 80 hex, call kernel

Offline Frank Kotler

  • NASM Developer
  • Hero Member
  • *****
  • Posts: 2667
  • Country: us
Re: undefined reference to WinMain@16
« Reply #3 on: February 24, 2007, 11:34:09 PM »
Oh, my! This code is for Linux, and won't run on Windows even if you *do* find WinMain@16 (four parameters????)

Subsequent examples on that site - calling printf - might run on Windows, but will need some changes. For Linux, "main", "printf" and friends *don't* want to begin with an underscore. For Windows, you want "_main", "_printf", etc. Nasm will help you with this! In addition to changing "-f elf" to "-f win32", add "--PREFIX _" to Nasm's command line. That will prepend an underscore to anything you've declared extern or global. You may need to "%define _main WinMain@16", too.

There may be other changes needed. We can discuss 'em if you're committed to assembling the code on the site you cite... but it's for Linux, and I think you'd be better off finding examples intended for Windows.

http://www.drpaulcarter.com/~pcasm

is good for Windows or Linux (or djgpp, or ???). There are Windows-specific examples in the "files" section of the !Yahoo! group "win32-nasm-users" (you'll have to "join" to get 'em, I think - worth it... not *much* spam...) Or look at the "Nasm32 project" at... uh, Google for it...

If you want to get the code on that page working on Windows, we can help you convert it, but it really doesn't seem worthwhile...

Best,
Frank