当使用SFML for GCC 4.7 MinGW(DW2) - 32位时,我得到以下未定义的引用:
g++ -std=c++11 -Wall -I$(SFML_INCLUDE) -o pong main.o
main.o:main.cpp: undefined reference to `_imp___ZN2sf6StringC1EPKc
RKSt6locale'
main.o:main.cpp: undefined reference to `_imp___ZN2sf9VideoModeC1E
jjj'
main.o:main.cpp: undefined reference to `_imp___ZN2sf12RenderWindo
wC1ENS_9VideoModeERKNS_6StringEjRKNS_15ContextSettingsE'
main.o:main.cpp: undefined reference to `_imp___ZN2sf11CircleShape
C1Efj'
....
....
....
collect2.exe: error: ld returned 1 exit status
make: *** [all] Error 1
除此之外还有很多。这就是我的链接方式:
LIBRARIES = -lsfml-graphics -lsfml-window -lglu32 -lopengl32 -lglew32
g++ -c include/main.cpp -L/lib $(LIBRARIES)
我在Windows上。如何摆脱这些未定义的引用?
编辑:这是该计划:
#define SFML_STATIC
#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;
}
答案 0 :(得分:4)
您已编译和链接混合。这是链接:
g++ -std=c++11 -Wall -I$(SFML_INCLUDE) -o pong main.o
这是编译:
g++ -c include/main.cpp -L/lib $(LIBRARIES)
链接而不是编译需要$(LIBRARIES)
变量和-L
选项。
g++ main.o -o pong -L/lib $(LIBRARIES)
编译需要-std=c++11
和-Wall
以及-I
。
g++ -std=c++11 -Wall -c -I$(SFML_INCLUDE) include/main.cpp