我现在想学习SFML库。 我的操作系统是Windows 8.1,我不使用任何IDE,只使用Makefile。编译器是g ++ MinGW 4.8.1
我从官方网站下载了SFML文件,然后将#SF;包含" - SFML文件夹复制到"包含" - MinGW的文件夹," lib"和" bin"太
现在我想在官方网站上编译简单的程序。
#include <SFML/Graphics.hpp>
int main()
{
sf::RenderWindow window(sf::VideoMode(200, 200), "SFML works!");
sf::CircleShape shape(100.f);
shape.setFillColor(sf::Color::Green);
while (window.isOpen())
{
sf::Event event;
while (window.pollEvent(event))
{
if (event.type == sf::Event::Closed)
window.close();
}
window.clear();
window.draw(shape);
window.display();
}
return 0;
}
使用这样的命令行
g ++ test.o -o main -lsfml-graphics -lsfml-window -lsfml-system
但我有很多这样的错误
test.o:test.cpp:(.text+0xe5): undefined reference to _imp___ZN2sf6StringC1EPKcRKSt6locale
我做错了什么?
我有一个猜测,可能是PATH变量有问题。但是我不明白我应该在那里写什么。
UPD:
这是所有链接器的错误:
test.o:test.cpp:(.text+0xe5): undefined reference to `_imp___ZN2sf6StringC1EPKcRKSt6locale'
test.o:test.cpp:(.text+0x10b): undefined reference to `_imp___ZN2sf9VideoModeC1Ejjj'
test.o:test.cpp:(.text+0x147): undefined reference to `_imp___ZN2sf12RenderWindowC1ENS_9VideoModeERKNS_6StringEjRKNS_15ContextSettingsE'
test.o:test.cpp:(.text+0x17d): undefined reference to `_imp___ZN2sf11CircleShapeC1Efj'
test.o:test.cpp:(.text+0x18e): undefined reference to `_imp___ZN2sf5Color5GreenE'
test.o:test.cpp:(.text+0x198): undefined reference to `_imp___ZN2sf5Shape12setFillColorERKNS_5ColorE'
test.o:test.cpp:(.text+0x1b8): undefined reference to `_imp___ZN2sf6Window5closeEv'
test.o:test.cpp:(.text+0x1cd): undefined reference to `_imp___ZN2sf6Window9pollEventERNS_5EventE'
test.o:test.cpp:(.text+0x1ff): undefined reference to `_imp___ZN2sf5ColorC1Ehhhh'
test.o:test.cpp:(.text+0x21a): undefined reference to `_imp___ZN2sf12RenderTarget5clearERKNS_5ColorE'
test.o:test.cpp:(.text+0x22d): undefined reference to `_imp___ZN2sf12RenderStates7DefaultE'
test.o:test.cpp:(.text+0x241): undefined reference to `_imp___ZN2sf12RenderTarget4drawERKNS_8DrawableERKNS_12RenderStatesE'
test.o:test.cpp:(.text+0x253): undefined reference to `_imp___ZN2sf6Window7displayEv'
test.o:test.cpp:(.text+0x262): undefined reference to `_imp___ZNK2sf6Window6isOpenEv'
test.o:test.cpp:(.text+0x28b): undefined reference to `_imp___ZN2sf12RenderWindowD1Ev'
test.o:test.cpp:(.text+0x2b2): undefined reference to `_imp___ZN2sf12RenderWindowD1Ev'
test.o:test.cpp:(.text+0x2ec): undefined reference to `_imp___ZN2sf12RenderWindowD1Ev'
c:/program files (x86)/mingw/bin/../lib/gcc/mingw32/4.8.1/../../../../mingw32/bin/ld.exe: test.o: bad reloc address 0xf in section `.text$_ZN2sf6StringD1Ev[__ZN2sf6StringD1Ev]'
c:/program files (x86)/mingw/bin/../lib/gcc/mingw32/4.8.1/../../../../mingw32/bin/ld.exe: final link failed: Invalid operation
collect2.exe: error: ld returned 1 exit status
SFML的版本是2.2
我仍然需要帮助(见下面的评论)