链接到SFML的未解决的外部错误(SFML 2.2,Visual Studio Community 2013)
Unresolved External errors linking to SFML (SFML 2.2, Visual Studio Community 2013)
试图将一个新的C++项目与SFML链接起来,我做了以下操作:
- 创建了一个空项目
- C/C++>>常规:附加包含目录:添加了SFML包含目录并从项目默认值继承
- 链接器>>附加库目录:添加了SFML lib目录并从项目默认值继承
- 添加了其他依赖项:winmm.lib、openal32.lib、sndfile.lib、opengl32.lib、gdi32.lib、glew.lib、freetype.lib、jpeg.lib、sfml-system-s-d.lib、sfml-audio-s-d.lib、sfml-window-s-d.libsfml-graphics-s-d.lib,以及从项目默认值继承
- 所有其他项目设置都是默认设置
我从中复制了示例main()http://www.sfml-dev.org/tutorials/2.0/start-vc.php。
当我尝试构建程序时,我得到15个LNK2019未解决的外部错误:
1>main.obj : error LNK2019: unresolved external symbol "__declspec(dllimport) public: __thiscall sf::String::String(char const *,class std::locale const &)" (__imp_??0String@sf@@QAE@PBDABVlocale@std@@@Z) referenced in function _main
1>main.obj : error LNK2019: unresolved external symbol "__declspec(dllimport) public: __thiscall sf::String::~String(void)" (__imp_??1String@sf@@QAE@XZ) referenced in function _main
1>main.obj : error LNK2019: unresolved external symbol "__declspec(dllimport) public: __thiscall sf::VideoMode::VideoMode(unsigned int,unsigned int,unsigned int)" (__imp_??0VideoMode@sf@@QAE@III@Z) referenced in function _main
1>main.obj : error LNK2019: unresolved external symbol "__declspec(dllimport) public: void __thiscall sf::Window::close(void)" (__imp_?close@Window@sf@@QAEXXZ) referenced in function _main
1>main.obj : error LNK2019: unresolved external symbol "__declspec(dllimport) public: bool __thiscall sf::Window::isOpen(void)const " (__imp_?isOpen@Window@sf@@QBE_NXZ) referenced in function _main
1>main.obj : error LNK2019: unresolved external symbol "__declspec(dllimport) public: bool __thiscall sf::Window::pollEvent(class sf::Event &)" (__imp_?pollEvent@Window@sf@@QAE_NAAVEvent@2@@Z) referenced in function _main
1>main.obj : error LNK2019: unresolved external symbol "__declspec(dllimport) public: void __thiscall sf::Window::display(void)" (__imp_?display@Window@sf@@QAEXXZ) referenced in function _main
1>main.obj : error LNK2019: unresolved external symbol "__declspec(dllimport) public: __thiscall sf::Color::Color(unsigned char,unsigned char,unsigned char,unsigned char)" (__imp_??0Color@sf@@QAE@EEEE@Z) referenced in function _main
1>main.obj : error LNK2019: unresolved external symbol "__declspec(dllimport) public: void __thiscall sf::RenderTarget::clear(class sf::Color const &)" (__imp_?clear@RenderTarget@sf@@QAEXABVColor@2@@Z) referenced in function _main
1>main.obj : error LNK2019: unresolved external symbol "__declspec(dllimport) public: void __thiscall sf::RenderTarget::draw(class sf::Drawable const &,class sf::RenderStates const &)" (__imp_?draw@RenderTarget@sf@@QAEXABVDrawable@2@ABVRenderStates@2@@Z) referenced in function _main
1>main.obj : error LNK2019: unresolved external symbol "__declspec(dllimport) public: __thiscall sf::RenderWindow::RenderWindow(class sf::VideoMode,class sf::String const &,unsigned int,struct sf::ContextSettings const &)" (__imp_??0RenderWindow@sf@@QAE@VVideoMode@1@ABVString@1@IABUContextSettings@1@@Z) referenced in function _main
1>main.obj : error LNK2019: unresolved external symbol "__declspec(dllimport) public: virtual __thiscall sf::RenderWindow::~RenderWindow(void)" (__imp_??1RenderWindow@sf@@UAE@XZ) referenced in function _main
1>main.obj : error LNK2019: unresolved external symbol "__declspec(dllimport) public: void __thiscall sf::Shape::setFillColor(class sf::Color const &)" (__imp_?setFillColor@Shape@sf@@QAEXABVColor@2@@Z) referenced in function _main
1>main.obj : error LNK2019: unresolved external symbol "__declspec(dllimport) public: __thiscall sf::CircleShape::CircleShape(float,unsigned int)" (__imp_??0CircleShape@sf@@QAE@MI@Z) referenced in function _main
1>main.obj : error LNK2019: unresolved external symbol "__declspec(dllimport) public: virtual __thiscall sf::CircleShape::~CircleShape(void)" (__imp_??1CircleShape@sf@@UAE@XZ) referenced in function _main
2 LNK2001未解决的外部:
1>main.obj : error LNK2001: unresolved external symbol "__declspec(dllimport) public: static class sf::Color const sf::Color::Green" (__imp_?Green@Color@sf@@2V12@B)
1>main.obj : error LNK2001: unresolved external symbol "__declspec(dllimport) public: static class sf::RenderStates const sf::RenderStates::Default" (__imp_?Default@RenderStates@sf@@2V12@B)
和LNK1120:
1>C:Users<user name>DocumentsDLLTestDebugDLLTest.exe : fatal error LNK1120: 17 unresolved externals
未生成任何程序。
我觉得我错过了一些显而易见的东西,这更可能是关于链接到DLL而不是SFML。我做错了什么?
解决方案:这是特定于SFML的:我链接到了静态版本的SFML DLL(名称中带有-s的DLL)。我切换到了动态版本(例如sfml-system-d.lib),并构建了项目,尽管要运行它,我需要将sfml DLL与可执行文件放在同一目录中。
您正在链接SFML库的静态调试版本。你真的想构建一个静态版本吗?如果是,则必须定义SFML_STATIC。否则,请删除库名称中的-s选项。
我认为dllspec(dllimport)意味着您正在尝试动态链接。需要定义SFML_STATIC,或者将dll放在工作目录中,并在其他库中更改名称。
相关文章:
- Visual Studio 2015:Extern "C" 和 "export" 关键字
- 为cl.exe(Visual Studio代码)指定命令行C++版本
- 试图在visual studio上用C++创建一个桌面应用程序
- 安装 SFML 后 Visual Studio 2015 中出现错误
- 静态链接 Visual Studio dll 到动态链接的 sfml 项目
- 使用 Visual Studio 2017 编译 SFML
- 内部编译器错误Visual Studio Community 2017与SFML API
- SFML 2.4.2 for Visual C++ 2017 使用 SFML 的 2015 版本
- Visual Studio代码 - 找不到SFML库
- 如何在Visual Studio 2017中设置SFML?
- 在 Visual Studio 中为 SFML 设置相对路径
- (Visual Studio)尝试用SFML库静态链接microsoft库时出现大量链接器错误
- 在 Visual Studio 中使用 SFML 在 X64 中编译时出现问题
- 链接到SFML的未解决的外部错误(SFML 2.2,Visual Studio Community 2013)
- Visual Studio链接器在链接SFML-2.1时出错
- Visual c++项目在用SFML加载纹理时意外崩溃
- 使用CMake编译Visual Studio 2012的SFML
- visual studio-C++SFML从地图返回所有精灵
- visual studio 2013-C++Sfml文本输出
- 其他人如何在没有Visual Studio的情况下运行我的SFML / C++项目