gpt4 book ai didi

c++ - SFML 的链接器错误

转载 作者:太空狗 更新时间:2023-10-29 20:38:44 25 4
gpt4 key购买 nike

在运行 Ubuntu、SFML 2.2 和 g++ 4.8 时,在示例 SFML 代码上运行 g++ -lsfml-window -lsfml-graphics -lsfml-system main.cpp 时出现一系列错误。 2.我已尝试从包管理器 (libsfml-dev) 重新安装 SFML,但没有任何效果。

示例 SFML 代码:

#include <SFML/Graphics.hpp>
#include <string>

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

错误信息:

/tmp/ccVG6GjG.o: In function `main':
main.cpp:(.text+0xf7): undefined reference to `sf::String::String(char const*, std::locale const&)'
main.cpp:(.text+0x115): undefined reference to `sf::VideoMode::VideoMode(unsigned int, unsigned int, unsigned int)'
main.cpp:(.text+0x148): undefined reference to `sf::RenderWindow::RenderWindow(sf::VideoMode, sf::String const&, unsigned int, sf::ContextSettings cons'
main.cpp:(.text+0x182): undefined reference to `sf::CircleShape::CircleShape(float, unsigned int)'
main.cpp:(.text+0x18e): undefined reference to `sf::Color::Green'
main.cpp:(.text+0x196): undefined reference to `sf::Shape::setFillColor(sf::Color const&)'
main.cpp:(.text+0x1b6): undefined reference to `sf::Window::close()'
main.cpp:(.text+0x1cf): undefined reference to `sf::Window::pollEvent(sf::Event&)'
main.cpp:(.text+0x1f7): undefined reference to `sf::Color::Color(unsigned char, unsigned char, unsigned char, unsigned char)'
main.cpp:(.text+0x214): undefined reference to `sf::RenderTarget::clear(sf::Color const&)'
main.cpp:(.text+0x22b): undefined reference to `sf::RenderStates::Default'
main.cpp:(.text+0x236): undefined reference to `sf::RenderTarget::draw(sf::Drawable const&, sf::RenderStates const&)'
main.cpp:(.text+0x245): undefined reference to `sf::Window::display()'
main.cpp:(.text+0x254): undefined reference to `sf::Window::isOpen() const'
main.cpp:(.text+0x27f): undefined reference to `sf::RenderWindow::~RenderWindow()'
main.cpp:(.text+0x2a9): undefined reference to `sf::RenderWindow::~RenderWindow()'
main.cpp:(.text+0x2ee): undefined reference to `sf::RenderWindow::~RenderWindow()'
/tmp/ccVG6GjG.o: In function `sf::CircleShape::~CircleShape()':
main.cpp:(.text._ZN2sf11CircleShapeD2Ev[_ZN2sf11CircleShapeD5Ev]+0x13): undefined reference to `vtable for sf::CircleShape'
main.cpp:(.text._ZN2sf11CircleShapeD2Ev[_ZN2sf11CircleShapeD5Ev]+0x1f): undefined reference to `vtable for sf::CircleShape'
main.cpp:(.text._ZN2sf11CircleShapeD2Ev[_ZN2sf11CircleShapeD5Ev]+0x2b): undefined reference to `sf::Shape::~Shape()'
collect2: error: ld returned 1 exit status

最佳答案

有两种方法可以解决这个问题。第一个是交换一些选项,因此命令如下所示:g++ main.cpp -lsfml-window -lsfml-graphics -lsfml-system。第二个选项是尝试将 g++ 更新到版本 4.9.2,这可以在 ubuntu 上实现 by doing this

关于c++ - SFML 的链接器错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30630689/

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