【发布时间】: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 库