简体   繁体   English

对“WinMain”的未定义引用:使用 Cygwin、SDL2 和 Netbeans 时

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

any help here would be appreciated.任何帮助在这里将不胜感激。 Ive really racked my brains at this, sooo.我真的绞尽脑汁在这,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.我已经安装了 cygwin 和 Netbeans,并且已经成功地开发、编译和运行了一个小的 SDL-1.2 Windows 游戏,没有任何问题。

The problem has come now that I have installed SDL2 and am trying to compile.现在问题来了,我已经安装了 SDL2 并且正在尝试编译。 Specifically the linking.具体链接。

Im doing the same as before, adding "libSDL2.a" and "libSDL2main.a" to the linker options for my project in Netbeans;我和以前一样,将“libSDL2.a”和“libSDL2main.a”添加到我在 Netbeans 中的项目的链接器选项中; but im getting the "undefined reference to `WinMain'" error但我收到“对‘WinMain’的未定义引用”错误

Now, ive looked into this and it seems that the linker cannot link my main() function to the WinMain one.现在,我对此进行了调查,似乎链接器无法将我的 main() 函数链接到 WinMain 函数。

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我看到的另一个答案是将“-lmingw32 -lSDLmain -lSDL”添加到链接器选项但我不使用mingw,我使用的是cygwin,cygwin相当于mingw32.lib

I guess the main question is: What are the options I give the linker if im using Cygwin, SDL2 and Netbeans?我想主要问题是:如果我使用 Cygwin、SDL2 和 Netbeans,我给链接器的选项是什么?

any help would be greatly appreciated.任何帮助将不胜感激。

Have you tested with an #undef main infront of your main ?您是否在#undef main前面使用了#undef 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 在 Cygwin 和 SDL 中使用 Netbeans,包括 SDL.h 会产生奇怪的错误


May also help:也可能有帮助:

I get "Undefined reference to 'WinMain@16'"我收到“对‘WinMain@16’的未定义引用”

Under Visual C++, you need to link with SDL2main.lib.在 Visual C++ 下,您需要与 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包括 Dev-C++ 在内的 gcc 构建环境下您需要链接“sdl-config --libs”的输出,通常为:-lmingw32 -lSDL2main -lSDL2 -mwindows

( http://wiki.libsdl.org/FAQWindows#I_get_.22Undefined_reference_to_.27WinMain.4016.27.22 ) ( 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:对于我刚刚用 Cygwin 构建的库,我添加了以下编译器标志:

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

This allowed me to build my library without the dreaded, "missing WinMain," error message.这使我能够在没有可怕的“缺少 WinMain”错误消息的情况下构建我的库。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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