我在让一切正常工作方面遇到了很多麻烦,以便我可以在 Windows 上开始开发,而不是 Linux,这是我在编码时通常使用的。我在尝试编译 SDL 程序时遇到了一个相当奇怪的问题。我一包含 SDL 库,程序就拒绝编译,给我这个错误:
c:/mingw/bin/../lib/gcc/mingw32/4.6.2/../../../libmingw32.a<main.o>: In function 'main':
C:\MinGW\msys\1.0\src\mingwrt/../mingw/main.c:73: undefined reference to 'WinMain@16'
collect2: ld returned 1 exist status
我在控制台上使用 MinGW。
举个例子,使用
gcc -o test main.c
这编译得很好:
#include <stdio.h>
#include <stdlib.h>
int main(int argv, char **argc)
{
printf("Hello, world!\n");
return 0;
}
但是只要我添加#include(即使没有调用任何 SDL 函数)我就会得到上面提到的错误
使用:
gcc -o test main.c -lSDL
编译失败:
#include <stdio.h>
#include <stdlib.h>
#include <SDL/SDL.h>
int main(int argv, char **argc)
{
printf("Hello, world!\n");
return 0;
}
任何帮助将不胜感激!我读到这是忘记拥有主要功能的人的常见问题,但显然这不是我的问题。我也听说WinMain是处理Windows图形程序时使用的主要函数,但我以前多在Windows开发,这对我来说从来都不是问题。
最佳答案
我搜索了一些有关此错误的更多信息,然后找到了 this page其中包括以下信息:
The only trick in getting this to compile now is to add the include path (eg: -I../SDL/include), the linker path (eg: -L../SDL/lib), and then finally adding the libraries themselves in the right order. Use:
-lmingw32 -lSDLmain -lSDL
Also, don't forget to add the -mwindows flag, if your IDE doesn't add it automatically (in addition to whatever other libraries you want to link). If you don't put them in the right order, you'll get a linker error complaining about the missing symbol WinMain@16.
尝试使用上面的那些标志重新编译,看看这是否有所不同。
关于c - 使用 SDL 时未定义对 WinMain@16 的引用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18115153/