gpt4 book ai didi

c++ - SFML 未定义对 impl 的引用

转载 作者:可可西里 更新时间:2023-11-01 11:18:28 24 4
gpt4 key购买 nike

将 SFML 用于 GCC 4.7 MinGW (DW2) - 32 位时,我得到以下 undefined reference :

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 上。我如何摆脱这些 undefined reference ?

编辑:这是程序:

#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;
}

最佳答案

您混淆了编译和链接。这是链接:

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

关于c++ - SFML 未定义对 impl 的引用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25594660/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com