如何获得最小的SDL程序来编译和链接在visual studio 2008 express? [英] How do you get a minimal SDL program to compile and link in visual studio 2008 express?
问题描述
我试图在Visual Studio 2008 Express中使用C ++中的SDL。以下程序编译但不链接:
I'm trying to use SDL in C++ with Visual Studio 2008 Express. The following program compiles but does not link:
#include <SDL.h>
int main(int argc, char *argv[])
{
return 0;
}
链接错误是:
LINK : fatal error LNK1561: entry point must be defined
无论如何或如果我链接到SDL.lib和SDLmain.lib,我得到这个。将主
定义为 main()
或 SDL_main()
相同的错误,有或没有 externC
。
I get this regardless of how or if I link with SDL.lib and SDLmain.lib. Defining main
as main()
or SDL_main()
gives the same error, with or without extern "C"
.
编辑:我解决这个不包括SDL。 h在main.cpp - 重构我独立的问题。类似的解决方案是在定义函数之前 #undef main
。
I solved this by not including SDL.h in main.cpp - a refactoring I did independent of the problem. A similar solution would be to #undef main
right before defining the function.
推荐答案
我目前没有VC ++可用,但我已经看过这个问题几次了。
I don't have VC++ available at the moment, but I have seen this issue several times.
您需要创建一个Win32项目而不是控制台项目。 Win32项目需要一个 WinMain 函数作为程序入口点。 SDLmain.lib包含此入口点,SDL_main.h头文件具有将您的主函数重新映射到SDL_main的宏。此函数由SDLmain库中的入口点调用。
You need to create a Win32 project as opposed to a console project. A Win32 project expects a WinMain function as a program entry point. SDLmain.lib contains this entry point and the SDL_main.h header file has a macro that remaps your main function to SDL_main. This function is called by the entry point in the SDLmain library.
主函数必须具有以下签名:
The main function must have the following signature:
int main(int argc, char *argv[])
它还需要在声明你的main函数之前包含SDL.h,并且你需要链接到SDL.lib和SDLmain.lib。
It is also required to include SDL.h before the declaration of your main function, and you need to link to both SDL.lib and SDLmain.lib.
它看起来像你在做这个。 所以,我的猜测是你有一个控制台项目设置。因此,链接器正在寻找一个主函数调用,但它被重新映射到SDL_main由宏SDL_main.h 。所以,链接器找不到一个入口点并放弃!
It looks like you are doing this. So, my guess is that you have a console project setup. Therefore, the linker is looking for a main function to call, but it is getting remapped to SDL_main by the macro SDL_main.h. So, the linker can't find an entry point and gives up!
这篇关于如何获得最小的SDL程序来编译和链接在visual studio 2008 express?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!