和main函数相关的问题 出现错误"Undefined reference to 'WinMain@16'" 在VisualC++中,你应该链接SDLmain.lib 在gcc构建环境中(包括DevC++ Codeblock之类的) 你都必须添加链接命令 -lmingw32 -lSDLmain -lSDL -mwindows 通常就是这些了,但不保证以后会不会变, 最靠谱的方法是直接看解压包里的sdl2-config文件里的 --libs 下面的那些命令。 译者注:以防万一,请按顺序加。直接复制是不错的选择。 I get "Undefined reference to 'WinMain@16'" Under Visual C++, you need to link with SDLmain.lib. Under the gcc build environments including Dev-C++, you need to link with the output of "sdl-config --libs", which is usually: -lmingw32 -lSDLmain -lSDL -mwindows "Undefined reference to 'SDL_main'" 你只应该如此声明main函数!!!!!!! int main(int argc, char *argv[]) 译者注 如果不用这些参数 ,可以把argc argv删去以消除编译警告。但参数类型必须与此等同。 你应该用main而非WinMain即使是你只在windows系统上写程序,因为SDL已经提供了一个WinMain, 并在执行你的main函数前先在SDL内置的Winmain里执行一些SDL相关的初始化。如果你因为某些原因必须使用WinMain的话, 那么请查看位于src/main/win32/SDL_main.c的源代码,去了解你需要在这里做哪些必要的初始化工作以使SDL正确工作。 I get "Undefined reference to 'SDL_main'" ... Make sure that you are declaring main() as: #include "SDL.h" int main(int argc, char *argv[]) You should be using main() instead of WinMain() even though you are creating a Windows application, because SDL provides a version of WinMain() which performs some SDL initialization before calling your main code. If for some reason you need to use WinMain(), take a look at the SDL source code in src/main/win32/SDL_main.c to see what kind of initialization you need to do in your WinMain() function so that SDL works properly. 不要用#undef SDL_main 之类的奇葩手段.