链接到 SFML 的未解决的外部错误(SFML 2.2,Visual Studio Community 2013)

Unresolved External errors linking to SFML (SFML 2.2, Visual Studio Community 2013)

提问人:ExOttoyuhr 提问时间:4/7/2015 最后编辑:nvoigtExOttoyuhr 更新时间:10/4/2016 访问量:4413

问:

尝试将新的 C++ 项目与 SFML 链接,我做了以下操作:

  • 创建了一个空项目。
  • C/C++ >> General: Additional Include Directories:添加了 SFML include 目录,并从项目默认值继承。
  • 链接器>>其他库目录:添加了 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.lib、sfml-graphics-s-d.lib,以及从项目默认值继承。
  • 所有其他项目设置均为默认设置。

我从 http://www.sfml-dev.org/tutorials/2.0/start-vc.php 中复制了示例 main()。

当我尝试构建程序时,我收到 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>\Documents\DLLTest\Debug\DLLTest.exe : fatal error LNK1120: 17 unresolved externals

不构建任何程序。

我觉得我错过了一些明显的东西,它更有可能是关于链接到 DLL 而不是关于 SFML。我做错了什么?

分辨率:这是特定于 SFML 的:我链接到 SFML DLL 的静态版本(名称中带有 -s 的版本)。我切换到动态版本(例如sfml-system-d.lib),并构建了项目,尽管要运行它,我需要将SFML DLL与可执行文件放在同一目录中。

C++ DLL 链接器 SFML 未解析的外部

评论

0赞 Timo Geusch 4/7/2015
请在您的问题中包含错误消息。
0赞 ExOttoyuhr 4/7/2015
添加了错误消息。

答:

6赞 kylecorver 4/7/2015 #1

您正在链接 SFML-Libs 的静态调试版本。你真的想构建一个静态版本吗?如果是这样,您必须定义SFML_STATIC。否则,请删除 Library-names 中的 -s 选项。

评论

0赞 ExOttoyuhr 4/8/2015
这做到了 - 看起来问题出在我使用的 SFML 库名称上。我以为这是显而易见的......感谢您的帮助!
1赞 Cygnuson 4/7/2015 #2

我认为dllspec(dllimport)意味着您正在尝试动态链接。需要定义SFML_STATIC,或者将 dll 放在工作目录中,并在其他库中更改名称。

评论

0赞 ExOttoyuhr 4/8/2015
谢谢!如果我也能接受你的回答,我会的。