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

本秂侑毒 提交于 2019-12-02 03:07:57

问题


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.


回答1:


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 )




回答2:


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.



来源:https://stackoverflow.com/questions/29846946/undefined-reference-to-winmain-when-using-cygwin-sdl2-and-netbeans

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!