c++ - Visual Studio 2017 中的 sfml 静态链接错误

标签 c++ windows visual-studio static-libraries sfml

一段时间以来,我在游戏编程方面遇到了一些问题。我不会说我是编程新手,但链接库对我来说是新事物。所以这是我的问题:当我开始编写 sfml 游戏时(我开始使用 .h 和 .cpp 文件,使用 sfml 2.5.1 64 位)我注意到我不能使用这些和类似的功能:

.setColor(Color::Black) / .setFillColor(Color::color)

我收到一条错误消息:

public: __thiscall sf::Color::Color(unsigned char,unsigned char,unsigned char,unsigned char)" (??0Color@sf@@QAE@EEEE@Z) already defined in sfml-graphics-d.lib(sfml-graphics-d-2.dll)

然后我发现我必须链接静态库才能正常工作,我这样做了,但是我收到了一个新错误:

module machine type 'x64' conflicts with target machine type 'X86'

我可能通过将“目标机器”更改为“未设置”来修复它,然后出现下一个 237 错误:

mismatch detected for 'RuntimeLibrary': value 'MDd_DynamicDebug' doesn't match value 'MTd_StaticDebug'

public: __cdecl std::_Lockit::_Lockit(int)" (??0_Lockit@std@@QEAA@H@Z) already defined in libcpmtd.lib(xlock.obj)

private: static class std::locale::_Locimp * __cdecl std::locale::_Init(bool)" (?_Init@locale@std@@CAPEAV_Locimp@12@_N@Z) already defined in libcpmtd.lib(locale0.obj)

unresolved external symbol __imp_cosf

unresolved external symbol __imp_sinf

还有很多这样的......基本上,几乎每一行都是错误的。

我找到了将运行时库更改为/MTd 的可能解决方案,但它似乎不起作用,因为我得到了相同的 237 错误。

可能是什么问题,我该如何解决?

提前谢谢你。

最佳答案

正如其他人提到的,您应该以 x86 为目标,因为您的二进制文件是这样做的。

至于多重定义,请确保您没有编译 .lib 文件,而只编译 SFML header 。

不要在任何地方包含 DLL,并确保为链接器设置正确的输入。

SFML 的网站有一个非常详尽的 getting started guide如果您正确地遵循它,您的链接将起作用。

我建议您重新开始,并按照教程一步步进行。此外,请确保阅读所有内容(跳过教程的一小部分是万恶之源。)

关于c++ - Visual Studio 2017 中的 sfml 静态链接错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54502922/

相关文章:

c++ - 如何在运行时创建一个包含 N 个整数的元组

c++ - c - 如何在资源管理器中打开选定的文件

c# - 如何在 C# 中获取当前用户的桌面路径?

windows - 使用哪个工具打开 .pdb(符号)文件?

c++ - C++ 中的 vector 与数组

visual-studio - 有没有一种方法可以在Visual Studio中自动为 "Additional Dependencies"生成 "Custom Build"?

c++ - C++ 中的迭代器和模板

C++ std::thread 在堆栈上

sql-server - 连接超时已过期。尝试使用登录前握手确认时超时时间已过

c++ - 单元测试 Boost 文件系统 create_directories