简体   繁体   English

使用SDL时对WinMain @ 16的未定义引用

[英]Undefined reference to WinMain@16 when using SDL

I've been having a lot of trouble getting everything working so that I can start developing on Windows, as apposed to Linux, which is what I normally use when coding. 为了使所有功能正常工作,我一直遇到很多麻烦,因此我可以像在Linux上那样开始在Windows上进行开发,这是我通常在编码时使用的语言。 I'm having a rather bizarre issue when trying to compile an SDL program. 尝试编译SDL程序时,我遇到了一个很奇怪的问题。 As soon as I include the SDL library, the program refuses to compile, giving me this error: 一旦包含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

I am using MinGW on console. 我在控制台上使用MinGW。

To give an example, using 举一个例子,使用

gcc -o test main.c

This compiles fine: 这样可以编译:

#include <stdio.h>
#include <stdlib.h>

int main(int argv, char **argc)
{
    printf("Hello, world!\n");

    return 0;
}

But as soon as I add #include (even without any SDL functions being called) I get the error mentioned above 但是,一旦我添加#include(即使没有调用任何SDL函数),我也会收到上述错误。

Using: 使用方法:

gcc -o test main.c -lSDL

This fails to compile: 无法编译:

#include <stdio.h>
#include <stdlib.h>

#include <SDL/SDL.h>

int main(int argv, char **argc)
{
    printf("Hello, world!\n");

    return 0;
}

Any help would be greatly appreciated! 任何帮助将不胜感激! I read that this was a common issue for people who forget to have a main function, but obviously that's not my issue. 我读到,对于那些忘记拥有主要功能的人来说,这是一个普遍的问题,但是显然这不是我的问题。 I also heard that WinMain is the main function used when dealing with Windows graphical programs, but that's never been an issue for me in the past when I used to develop in Windows more. 我还听说WinMain是处理Windows图形程序时使用的主要功能,但是当我过去在Windows中进行更多开发时,这对我来说从来就不是问题。

I did a little bit of searching for some more information on this error, and I found this page which includes the following informaion: 我做了一些搜索以查找有关此错误的更多信息,然后发现此页面包含以下信息:

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. 立即编译此文件的唯一技巧是添加包含路径(例如:-I ../ SDL / include),链接器路径(例如:-L ../ SDL / lib),然后最终添加库自己以正确的顺序。 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). 另外,如果您的IDE不会自动添加-mwindows标志(除了您要链接的其他任何库),请不要忘记添加-mwindows标志。 If you don't put them in the right order, you'll get a linker error complaining about the missing symbol WinMain@16. 如果您未按正确的顺序排列它们,则会收到链接器错误,抱怨缺少符号WinMain @ 16。

Try recompiling with those flags above and see whether that makes a difference. 尝试使用上面的那些标志重新编译,看看是否有区别。

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

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