我已经设置了 Netbeans C/C++,安装、配置并正确运行了 Cygwin。 SDL 是使用 Cygwin 终端从源安装的。我已经确认 Cygwin、Netbeans 和 SDL 都运行正确,我可以使用 Netbeans 编写和编译 C++ 项目,并且 Netbeans 可以看到 SDL,而无需包含任何文件或任何内容,它就像默认库一样工作。
#include <cstdlib>
#include <sdl2/SDL.h>
using namespace std;
int main(int argc, char** argv) {
return 0;
}
这是我试图编译的代码,Netbeans 没有突出显示 sdl.h 的包含内容,但是当我去构建时,我得到了这个:
"/usr/bin/make" -f nbproject/Makefile-Debug.mk QMAKE= SUBPROJECTS= .build-conf
make[1]: Entering directory '/home/Cally/Projects/Test'
"/usr/bin/make" -f nbproject/Makefile-Debug.mk dist/Debug/Cygwin_4.x-Windows/test.exe
make[2]: Entering directory '/home/Cally/Projects/Test'
mkdir -p build/Debug/Cygwin_4.x-Windows
rm -f "build/Debug/Cygwin_4.x-Windows/main.o.d"
g++ -c -g -MMD -MP -MF "build/Debug/Cygwin_4.x-Windows/main.o.d" -o build/Debug/Cygwin_4.x-Windows/main.o main.cpp
mkdir -p dist/Debug/Cygwin_4.x-Windows
g++ -o dist/Debug/Cygwin_4.x-Windows/test build/Debug/Cygwin_4.x-Windows/main.o
/usr/lib/gcc/x86_64-pc-cygwin/4.8.3/../../../../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 status
nbproject/Makefile-Debug.mk:62: recipe for target 'dist/Debug/Cygwin_4.x-Windows/test.exe' failed
make[2]: *** [dist/Debug/Cygwin_4.x-Windows/test.exe] Error 1
make[2]: Leaving directory '/home/Cally/Projects/Test'
nbproject/Makefile-Debug.mk:59: recipe for target '.build-conf' failed
make[1]: *** [.build-conf] Error 2
make[1]: Leaving directory '/home/Cally/Projects/Test'
nbproject/Makefile-impl.mk:39: recipe for target '.build-impl' failed
make: *** [.build-impl] Error 2
BUILD FAILED (exit value 2, total time: 1s)
当我不包含 SDL 时,构建成功。有人知道我做错了什么吗?
错误消息看起来真的很邪恶 - 但它只是告诉你它找不到WinMain
.
这是 SDL 的一个已知问题。请将这些库添加到您的链接器中(订单是强制性的!):
mingw32
SDLmain
SDL
您可以添加-lmingw32 -lSDLmain -lSDL
链接器选项或通过链接器配置的库菜单添加它们。
有可能你需要SDL_mixer
也是 - 如果是这样,只需最后添加即可。
另请参阅:http://content.gpwiki.org/index.php/SDL%3aTutorials%3aSetup http://content.gpwiki.org/index.php/SDL%3aTutorials%3aSetup
As a “肮脏的解决方法”你可以这样做:取消定义main
.
SDL 重新定义main()
作为带有一些附加内容的宏。你可以通过egl来验证这一点。Ctrl + 单击在主要/转到声明/定义或者检查它的格式是否为makro。
#include <cstdlib>
#include <sdl2/SDL.h>
using namespace std;
/*
* 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;
}
请参阅来源SDL_main.h http://hg.libsdl.org/SDL/file/f061a86fbb08/include/SDL_main.h(第 103 行+)。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)