【问题标题】:Linker errors in dev c++ while linking SFML files链接 SFML 文件时 dev c++ 中的链接器错误
【发布时间】:2020-07-10 22:05:55
【问题描述】:

我在 main.cpp 文件中附加了 SFML 文件,用于用 c++ 编写一些游戏。我想添加一些图像,所以我在以下内容的帮助下包含了 SFML 文件:

#include <SFML/Graphics.hpp>
#include <time.h>
using namespace sf;

当我编译我的源代码时,出现链接器错误,例如

发生了对 __imp 的未定义引用。

以下是错误:

[Linker error] C:\Users\BILAWA~1\AppData\Local\Temp\ccYKolqi.o:main.cpp:(.text+0x2b6): undefined reference to `__imp__ZN2sf6StringC1EPKcRKSt6locale'
[Linker error] C:\Users\BILAWA~1\AppData\Local\Temp\ccYKolqi.o:main.cpp:(.text+0x2e1): undefined reference to `__imp__ZN2sf9VideoModeC1Ejjj'
[Linker error] C:\Users\BILAWA~1\AppData\Local\Temp\ccYKolqi.o:main.cpp:(.text+0x335): undefined reference to `__imp__ZN2sf12RenderWindowC1ENS_9VideoModeERKNS_6StringEjRKNS_15ContextSettingsE'
[Linker error] C:\Users\BILAWA~1\AppData\Local\Temp\ccYKolqi.o:main.cpp:(.text+0x374): undefined reference to `__imp__ZN2sf7TextureC1Ev'
[Linker error] C:\Users\BILAWA~1\AppData\Local\Temp\ccYKolqi.o:main.cpp:(.text+0x38e): undefined reference to `__imp__ZN2sf7TextureC1Ev'
[Linker error] C:\Users\BILAWA~1\AppData\Local\Temp\ccYKolqi.o:main.cpp:(.text+0x3a8): undefined reference to `__imp__ZN2sf7TextureC1Ev'
[Linker error] C:\Users\BILAWA~1\AppData\Local\Temp\ccYKolqi.o:main.cpp:(.text+0x418): undefined reference to `__imp__ZN2sf7Texture12loadFromFileERKSsRKNS_4RectIiEE'
[Linker error] C:\Users\BILAWA~1\AppData\Local\Temp\ccYKolqi.o:main.cpp:(.text+0x4ad): undefined reference to `__imp__ZN2sf7Texture12loadFromFileERKSsRKNS_4RectIiEE'
[Linker error] C:\Users\BILAWA~1\AppData\Local\Temp\ccYKolqi.o:main.cpp:(.text+0x542): undefined reference to `__imp__ZN2sf7Texture12loadFromFileERKSsRKNS_4RectIiEE'
[Linker error] C:\Users\BILAWA~1\AppData\Local\Temp\ccYKolqi.o:main.cpp:(.text+0x588): undefined reference to `__imp__ZN2sf6SpriteC1ERKNS_7TextureE'
[Linker error] C:\Users\BILAWA~1\AppData\Local\Temp\ccYKolqi.o:main.cpp:(.text+0x5ca): undefined reference to `__imp__ZN2sf6SpriteC1ERKNS_7TextureE'
[Linker error] C:\Users\BILAWA~1\AppData\Local\Temp\ccYKolqi.o:main.cpp:(.text+0x615): undefined reference to `__imp__ZN2sf5ClockC1Ev'
[Linker error] C:\Users\BILAWA~1\AppData\Local\Temp\ccYKolqi.o:main.cpp:(.text+0x634): undefined reference to `__imp__ZNK2sf5Clock14getElapsedTimeEv'
[Linker error] C:\Users\BILAWA~1\AppData\Local\Temp\ccYKolqi.o:main.cpp:(.text+0x655): undefined reference to `__imp__ZNK2sf4Time9asSecondsEv'
[Linker error] C:\Users\BILAWA~1\AppData\Local\Temp\ccYKolqi.o:main.cpp:(.text+0x670): undefined reference to `__imp__ZN2sf5Clock7restartEv'
[Linker error] C:\Users\BILAWA~1\AppData\Local\Temp\ccYKolqi.o:main.cpp:(.text+0x6a7): undefined reference to `__imp__ZN2sf6Window5closeEv'
[Linker error] C:\Users\BILAWA~1\AppData\Local\Temp\ccYKolqi.o:main.cpp:(.text+0x713): undefined reference to `__imp__ZN2sf6Window9pollEventERNS_5EventE'
[Linker error] C:\Users\BILAWA~1\AppData\Local\Temp\ccYKolqi.o:main.cpp:(.text+0x730): undefined reference to `__imp__ZN2sf8Keyboard12isKeyPressedENS0_3KeyE'
[Linker error] C:\Users\BILAWA~1\AppData\Local\Temp\ccYKolqi.o:main.cpp:(.text+0xd5c): undefined reference to `__imp__ZN2sf5Color5WhiteE'
[Linker error] C:\Users\BILAWA~1\AppData\Local\Temp\ccYKolqi.o:main.cpp:(.text+0xd71): undefined reference to `__imp__ZN2sf12RenderTarget5clearERKNS_5ColorE'
[Linker error] C:\Users\BILAWA~1\AppData\Local\Temp\ccYKolqi.o:main.cpp:(.text+0xd81): undefined reference to `__imp__ZN2sf12RenderStates7DefaultE'
[Linker error] C:\Users\BILAWA~1\AppData\Local\Temp\ccYKolqi.o:main.cpp:(.text+0xda0): undefined reference to `__imp__ZN2sf12RenderTarget4drawERKNS_8DrawableERKNS_12RenderStatesE'
[Linker error] C:\Users\BILAWA~1\AppData\Local\Temp\ccYKolqi.o:main.cpp:(.text+0xe76): undefined reference to `__imp__ZN2sf6Sprite14setTextureRectERKNS_4RectIiEE'
[Linker error] C:\Users\BILAWA~1\AppData\Local\Temp\ccYKolqi.o:main.cpp:(.text+0xec0): undefined reference to `__imp__ZN2sf13Transformable11setPositionEff'
collect2: ld returned 1 exit status 

这样的错误还有很多。

【问题讨论】:

  • 您需要说明您的编译器/链接器以及如何调用它。显然你没有链接到正确的 SFML 库

标签: linker sfml dev-c++


【解决方案1】:

如果您使用的是 IDE,我会想做这样的事情: (右键单击您的项目,单击构建选项,然后单击链接器设置) 如果没有像 sanka 说的那样做

【讨论】:

    【解决方案2】:

    在 SFML 中,您需要使用一些标志进行编译:

    g++ -o ... -lsfml-graphics -lsfml-window -lsfml-system
    

    【讨论】:

      猜你喜欢
      • 2015-08-18
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2010-12-28
      • 2018-06-27
      • 2018-12-03
      • 1970-01-01
      • 2015-08-28
      相关资源
      最近更新 更多