简体   繁体   中英

undefined reference to `WinMain' : When using Cygwin, SDL2 and Netbeans

any help here would be appreciated. Ive really racked my brains at this, sooo.

I have installed cygwin, and Netbeans and have been successfully deving, compiling and running a small SDL-1.2 windows game with no problems.

The problem has come now that I have installed SDL2 and am trying to compile. Specifically the linking.

Im doing the same as before, adding "libSDL2.a" and "libSDL2main.a" to the linker options for my project in Netbeans; but im getting the "undefined reference to `WinMain'" error

Now, ive looked into this and it seems that the linker cannot link my main() function to the WinMain one.

Also one answer ive seen is to add "-lmingw32 -lSDLmain -lSDL" to the linker options BUT I dont use mingw, im using cygwin, whats the cygwin equivalent of mingw32.lib

I guess the main question is: What are the options I give the linker if im using Cygwin, SDL2 and Netbeans?

any help would be greatly appreciated.

Have you tested with an #undef main infront of your main ?

/*
 * If 'main' is defined we clear that definition
 * to get our default 'main' function back.
 */
#ifdef main
# undef main
#endif /* main */

int main(int argc, char** argv)
{
    // ...
    return 0;
}

Using Netbeans with Cygwin and SDL, including SDL.h creates strange error


May also help:

I get "Undefined reference to 'WinMain@16'"

Under Visual C++, you need to link with SDL2main.lib. Under the gcc build environments including Dev-C++, you need to link with the output of "sdl-config --libs", which is usually: -lmingw32 -lSDL2main -lSDL2 -mwindows

( http://wiki.libsdl.org/FAQWindows#I_get_.22Undefined_reference_to_.27WinMain.4016.27.22 )

For a library that I just built with Cygwin, I added the following compiler flags:

 -shared -Wl,--out-implib,lib$(LIB_NAME).dll.a

This allowed me to build my library without the dreaded, "missing WinMain," error message.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM