Undefined reference to WinMain in Cygwin
24,801
Use -c compile flag to only produce object file. Without -c it tries to link an executable and the linker (called automatically) fails.
Related videos on Youtube
Comments
-
Fawad Nasim about 2 yearsI am trying to compile and having following problem
$ gcc errlib.c -o errlib.o /usr/lib/gcc/x86_64-pc-cygwin/4.8.2/../../../../lib/libcygwin.a(libcmain.o): In function `main': /usr/src/debug/cygwin-1.7.30-1/winsup/cygwin/lib/libcmain.c:39: undefined reference to `WinMain' /usr/src/debug/cygwin-1.7.30-1/winsup/cygwin/lib/libcmain.c:39:(.text.startup+0x7e): relocation truncated to fit: R_X86_64_PC32 against undefined symbol `WinMain' collect2: error: ld returned 1 exit statusAny suggestions? These files are well tested and generated the code fine before but now i think there might be some cygwin settings or so ... m compiling on windows 8 on cygwin.
-
Zanna almost 4 years"gcc errlib.c -o errlib.o" is very confusing (it would generate an executable file with extension .o). It should be "gcc -c errlib.c", to generate the object file errlib.o; or "gcc errlib.c -o errlib.exe", to generate the executable file.
-
-
Fawad Nasim over 8 yearsbut now if I $ gcc addtcpc.c -o addtcpc -l sockwrap errlib gcc: error: errlib: No such file or directory however if i list ls addtcpc.c errlib.c sockwrap.c errlib.h sockwrap.h errlib.o sockwrap.o -
Paul over 8 years@user3448716 Then I don't fully understand your problem. If you just need to produce object file from source file (without linking an executable) you need to use-c. If you need to compile several sources and automatically link the executable after that you don't need to use-c. Please describe your workflow and what you are trying to achieve. -
Fawad Nasim over 8 yearsIn fact I have one file say xyz.c but this file use some functions defined in other 2 files named abc.h abc.c and def.h and def.c. Its not working when I do gcc xyz.c -o xyz -l abc.h def.h -
Paul over 8 yearsTrygcc xyz.c abc.c def.c. Note that you need to havemain()defined in one of these.cfiles.-Iis used to tell compiler wich directories to scan for include files, not to supply header file names. You should#include "abc.h"and#include "def.h"in yourxyz.cand also compileabc.canddef.c. That's whatgcc xyz.c abc.c def.cdoes. -
Aritro Shome over 1 year@Paulgcc xyz.c abc.c def.cproduces executable name a.exe, maybe we should also use the-oflag to specify output executable name so that there is no confusion while execution.