0

I'm trying to link a simple assembly code using gcc but i get the compile error Undefined reference to "WinMain@16". I'm currently using Windows and NASM to compile.

Compile command using nasm defaults

nasm -fwin32 C:\Users\james\Desktop\hello.asm

link command gcc using defaults

gcc C:\Users\james\Desktop\hello.o -o hello.exe

installed using Mingw code:

extern _printf
global _main

section .data
msg: db "Hello, world!",10,0

section .text
_main:
    push msg
    call _printf
    add esp,4   
    ret

using win os 10 Toshiba laptop.

rkhb
  • 14,159
  • 7
  • 32
  • 60
Roblox Man225
  • 75
  • 1
  • 8
  • 1
    Possible duplicate of [What is an undefined reference/unresolved external symbol error and how do I fix it?](http://stackoverflow.com/questions/12573816/what-is-an-undefined-reference-unresolved-external-symbol-error-and-how-do-i-fix) – Ken White Oct 25 '16 at 02:05
  • Change _main to WinMain. It seems windows gcc is looking for WinMain as its entry point. – hesham_EE Oct 25 '16 at 02:10
  • 1
    There are ton of hits on [undefined winmain](http://stackoverflow.com/search?q=undefined+winmain). The answer is the same: You are compiling as a GUI program, and GUI programs use WinMain. If you didn't want a GUI program, then fix your linker flags so it doesn't specify a GUI program. – Raymond Chen Oct 25 '16 at 02:24

0 Answers0