【问题标题】:Issue with compiling SFML project in CodeBlocks在 CodeBlocks 中编译 SFML 项目的问题
【发布时间】:2021-05-31 13:02:22
【问题描述】:

使用 SFML 在 c++ 中制作了一个简单的基于 sprite 的 2d 游戏。它在 linux 上编译和运行都很好,但我希望能够在 windows 上编译它

我已经从https://www.sfml-dev.org/download/sfml/2.5.1/ 下载了(假定的)正确版本的 sfml for code::blocks this one 并相应地配置了 GNU GCC 编译器搜索路径:

compiler search paths

linker search paths

c++11 standard enabled

运行代码后,我收到 152 个“未定义的对...的引用”错误

然后在将库添加到链接器设置之后

linker settings

我遇到了这 12 个错误:

||=== 构建文件:“无项目”中的“无目标”(编译器:未知)===| C:\sfmltest\main.o:main.cpp||未定义对_imp___ZN2sf5Music12openFromFileERKSs'| C:\sfmltest\main.o:main.cpp|| undefined reference to _imp___ZN2sf5Music12openFromFileERKSs'的引用 C:\sfmltest\main.o:main.cpp||未定义对_imp___ZN2sf5Music12openFromFileERKSs'| C:\sfmltest\main.o:main.cpp|| undefined reference to _imp___ZN2sf5Music12openFromFileERKSs'的引用 C:\sfmltest\main.o:main.cpp||未定义对_imp___ZN2sf4Font12loadFromFileERKSs'| C:\sfmltest\main.o:main.cpp|| undefined reference to _imp___ZN2sf7Texture12loadFromFileERKSsRKNS_4RectIiEE'的引用 C:\sfmltest\main.o:main.cpp||未定义对_imp___ZN2sf7Texture12loadFromFileERKSsRKNS_4RectIiEE'| C:\sfmltest\main.o:main.cpp|| undefined reference to _imp___ZN2sf7Texture12loadFromFileERKSsRKNS_4RectIiEE'的引用 C:\sfmltest\main.o:main.cpp||未定义对_imp___ZN2sf7Texture12loadFromFileERKSsRKNS_4RectIiEE'| C:\sfmltest\main.o:main.cpp|| undefined reference to _imp___ZN2sf7Texture12loadFromFileERKSsRKNS_4RectIiEE'的引用 C:\sfmltest\main.o:main.cpp||更多未定义的对 `_imp___ZN2sf7Texture12loadFromFileERKSsRKNS_4RectIiEE' 的引用如下| ||错误:ld 返回 1 个退出状态| ||=== 构建失败:12 个错误,0 个警告(0 分钟,2 秒)===|

我错过了什么?

【问题讨论】:

  • 通常名称中带有 d 的库是 Debug 库,没有它的是 Release。与他们联系起来非常奇怪。尝试仅链接 d-libraries 或仅链接 no-d-libraries。您可以为 Debug && Release 定义不同的集合。我想知道它是否有帮助。
  • lsfml-system lsfml-window lsfml-graphics 添加到构建选项下的链接库(对于代码::块 v20.03)应该就足够了,您可以尝试将这些添加到您的链接器设置中吗? (如果您使用的是网络和音频,只需通过替换后缀来添加它们)

标签: c++ gcc codeblocks sfml


【解决方案1】:

您没有定义SFML_STATIC,这就是链接器寻找_imp___(即导入)符号的原因。

您列出的库也是错误的。您应该只列出一组库。
例如静态和调试 = sfml-*-s-d
或静态和释放 = sfml-*-s

而且在静态链接的时候,还需要链接SFML的依赖。

如果您按照official tutorial 一步一步地使用 Code::Blocks 设置 SFML 并且不只是查看图像,那么一切都会正常工作。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2013-07-24
    • 2021-09-04
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多