在本地环境中使用SDL编译未定义对“WinMain”的引用 [英] undefined reference to 'WinMain' with SDL compiling in a native enviroment

查看:2260
本文介绍了在本地环境中使用SDL编译未定义对“WinMain”的引用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在努力与我的第一步在SDL。
我想编译一个简单的测试类,只包括SDL2头,没有什么特别的启动:

i'm struggeling with my first steps in SDL. I wanted to compile a simple test class, just including the SDL2 header, nothing special for startup:

main.cpp:

#include <SDL.h>

int main() {
    return 0;
}

main.cpp本身编译得很好:
g ++ -c main.cpp -ISDL / include

main.cpp itself compiles fine: g++ -c main.cpp -ISDL/include

但是一旦我想将其与SDL2.dll链接machinecode main.o或直接,我得到这个错误:
g ++ main.cpp -o sdl_test -I SDL / include -L SDL / lib / x64 -l SDL2 -mwindows
g ++ -o test main.o -L SDL / lib / x64 -l SDL2 -mwindows

but as soon as i want to link it with the SDL2.dll either with the machinecode main.o or directly, i'm getting this error: g++ main.cpp -o sdl_test -I SDL/include -L SDL/lib/x64 -l SDL2 -mwindows g++ -o test main.o -L SDL/lib/x64 -l SDL2 -mwindows

/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: Fehler: ld gab 1 als Ende-Status zurück

附加信息:
我使用Cygwin和显然g ++编译我的c ++代码。我的操作系统是Windows 7 Professional 64Bit SP 1。

Additional Information: I use Cygwin and obviously g++ to compile my c++ code. My OS is Windows 7 Professional 64Bit SP 1.

我googled了几个小时,但所有的结果,我遇到了说使用-mwindows编译一个非控制台应用程序或其他东西

I googled for several hours but all the results i came across said use -mwindows to compile a non console application or other things which didn't worked out.

感谢提前

推荐答案

当您使用 SDL 时,您的 main()必须类似于 int main ,char **)(或 int main(int argc,char ** argv))。

When you're using SDL, your main() must look like int main(int, char **) (or int main(int argc, char **argv)).

为什么?因为,在SDL代码里面你可以找到

Why? Because, somewhere inside SDL code you can find

int SDL_main(int, char **);

int main(int argc, char **argv)
{
    /*Some stuff.*/

    SDL_main(argc, argv);

    /*Some stuff.*/
}

然后, SDL.h 中:

#define main SDL_main

这篇关于在本地环境中使用SDL编译未定义对“WinMain”的引用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆