0

I'm trying to compile on Windows a project usually running on MacOSX. I have a makefile and I would like to use it on Windows too. The thing is that I don't understand this error:

/usr/lib/gcc/x86_64-pc-cygwin/7.3.0/../../../../lib/libcygwin.a(libcmain.o): In function `main':
/usr/src/debug/cygwin-2.11.2-1/winsup/cygwin/lib/libcmain.c:37: undefined reference to `WinMain'
/usr/src/debug/cygwin-2.11.2-1/winsup/cygwin/lib/libcmain.c:37:(.text.startup+0x7f): relocation truncated to fit: R_X86_64_PC32 against undefined symbol `WinMain'
collect2: error: ld returned 1 exit status
make: *** [makefile:70: program] Error 1

The compilation command was:

g++ -o program path/to/a/lot/of/obj/obj.o -lGLEW -lGLU -lGL -lSDL2main -lSDL2

There's a similar topic Undefined reference to WinMain in Cygwin but the solution didn't help me. My makefile works fine on MacOSX.

genpfault
  • 51,148
  • 11
  • 85
  • 139
kipgon
  • 131
  • 14
  • 1
    Why are you trying to build an OpenGL app via Cygwin? It won't work the way you expect it to work, since it will end up using `glX` instead of `wgl`, and will require an X server. It would be a much better idea to try to build this stuff on a native windows compiler toolchain like mingw or even Visual Studio (Community). – derhass Mar 28 '20 at 12:15
  • I'm trying with cygwin in order to use my makefile which should allows me to compile easily my project on multiple platforms because I have to. I didn't know that for OpenGL that is not possible. I'm not familiar with MinGW. What's be the easiest way to build my project from command line ? Is it possible to use a makefile ? – kipgon Mar 28 '20 at 12:31
  • 1
    `mingw` provides a whole toolchain including GNU make (and a package manager, and libraries like SDL) - actually the mingw toolchain even uses cygwin, but in contrast to cygwin, the compilers and libraries actually target the native win32 APIs instead of the unix ones that cygwin does. – derhass Mar 28 '20 at 12:35
  • @kipgon judging by error message it should be `g++ -o program path/to/a/lot/of/obj/obj.o -lGLEW -lGLU -lGL -lcygwin -lSDL2main -lSDL2` – keltar Mar 28 '20 at 19:16
  • 1
    @kipgon You probably want MSYS2 instead of Cygwin. It also provides a linux-like shell (including `make`), but uses a MinGW compiler. – HolyBlackCat Mar 28 '20 at 23:00
  • Thanks for all your comments. Using MinGW helped me a lot and I finally manage to compile my application with `mingw32-make`. Even if I had to modify some portion of my makefile (for exemple `rm` by `del` etc.). Maybe with MSYS2 that could be easier. The thing is that, now, I can only run my app from command line, it doesn't work by double clicking on it and it doesn't ask for missing .dll. – kipgon Mar 29 '20 at 16:16
  • Sorry for my last comment, that's was due to a mistake. Everything is working fine. Thank you for your help ! – kipgon Mar 29 '20 at 16:56
  • @keltar I tried your solution but it didn't work. Thanks by the way. – kipgon Mar 29 '20 at 16:57
  • @kipgon it's usually advisable not to use thanks in comments. see https://stackoverflow.com/help/privileges/comment – Aritro Shome Jul 20 '21 at 14:41

0 Answers0