我已经得到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
作为"肮脏的解决方案"你可以这样做:undefine main
.
SDL将main()
重新定义为带有一些附加内容的宏。你可以用egl来验证。Ctrl + click main/转到声明/定义或检查是否格式化为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
的来源(第103行+)