我为尝试将SDL库与MVS 2010中的新C ++ Win32 Console应用程序链接而感到困惑。
我下载了最新的SDL开发库,并执行了通常的步骤:
将includes添加到include路径(pic)中[这很好,因为MVS找到了#include文件]
添加了SDL(pic)的库路径[这似乎很好,因为删除此附加路径会出现错误“错误LNK1104:无法打开文件'SDL.lib'”]]
将SDL.lib和SDLmain.lib添加到链接器其他依赖项(pic)
我编辑了主文件以包含一些测试代码,使其看起来像这样:
#include "stdafx.h"
#include <iostream>
#include <stdlib.h>
#include "SDL.h"
int _tmain(int argc, _TCHAR* argv[])
{
int a;
SDL_Init(SDL_INIT_AUDIO|SDL_INIT_VIDEO);
std::cout << "Pong" << std::endl;
std::cin >> a;
return 0;
}
当我编译时,出现以下链接器错误:
Error 1 error LNK2019: unresolved external symbol _SDL_Init referenced in function _wmain D:\All\Proyects\PFC\RT-Pong\RT-Pong\RT-Pong\RT-Pong.obj RT-Pong
Error 2 error LNK1120: 1 unresolved externals D:\All\Proyects\PFC\RT-Pong\RT-Pong\Debug\RT-Pong.exe 1 1 RT-Pong
万一我的.lib损坏了,我又从0开始重新下载了整个文件,并得到了相同的结果。老实说,我很沮丧,这很像是我忽略的一个粗心的简单错误。因此,如果有人对此事有新的见解,那真的会让我感到高兴。
谢谢,
海梅
最佳答案
我认为由于“在SDL的库路径中定义的路径错误”而导致链接错误
在Project->Properties->Configuration Properties->Linker->General->Additional Library Directories
更改路径:D:\All\Proyects\PFC\RT-Pong\SDL-1.2.15\lib\x64
改为:D:\All\Proyects\PFC\RT-Pong\SDL-1.2.15\lib\x86