【问题标题】:code::Blocks | SFML errors代码::块 | SFML 错误
【发布时间】:2013-05-01 07:27:28
【问题描述】:

我正在尝试让 SFML 在 code::blocks 上工作,但每当我尝试测试示例代码时,我都会不断收到错误消息。我按照http://www.sfml-dev.org/tutorials/2.0/start-cb.php 的教程进行操作,但它似乎不起作用。

我不是很擅长这个,所以如果有人能帮忙就太好了。

这里是代码和错误的截图:http://i39.tinypic.com/nbdysj.jpg

以下是错误:

obj\Debug\test.o||In function `main':|
C:\Users\Mads\Desktop\test\test.cpp|5|undefined reference to `sf::String::String(char const*, std::locale const&)'|
C:\Users\Mads\Desktop\test\test.cpp|5|undefined reference to `sf::VideoMode::VideoMode(unsigned int, unsigned int, unsigned int)'|
C:\Users\Mads\Desktop\test\test.cpp|5|undefined reference to `sf::RenderWindow::RenderWindow(sf::VideoMode, sf::String const&, unsigned int, sf::ContextSettings const&)'|
C:\Users\Mads\Desktop\test\test.cpp|6|undefined reference to `sf::CircleShape::CircleShape(float, unsigned int)'|
C:\Users\Mads\Desktop\test\test.cpp|5|undefined reference to `sf::RenderWindow::~RenderWindow()'|
C:\Users\Mads\Desktop\test\test.cpp|7|undefined reference to `sf::Color::Green'|
C:\Users\Mads\Desktop\test\test.cpp|7|undefined reference to `sf::Shape::setFillColor(sf::Color const&)'|
C:\Users\Mads\Desktop\test\test.cpp|15|undefined reference to `sf::Window::close()'|
C:\Users\Mads\Desktop\test\test.cpp|12|undefined reference to `sf::Window::pollEvent(sf::Event&)'|
C:\Users\Mads\Desktop\test\test.cpp|18|undefined reference to `sf::Color::Color(unsigned char, unsigned char, unsigned char, unsigned char)'|
C:\Users\Mads\Desktop\test\test.cpp|18|undefined reference to `sf::RenderTarget::clear(sf::Color const&)'|
C:\Users\Mads\Desktop\test\test.cpp|19|undefined reference to `sf::RenderStates::Default'|
C:\Users\Mads\Desktop\test\test.cpp|19|undefined reference to `sf::RenderTarget::draw(sf::Drawable const&, sf::RenderStates const&)'|
C:\Users\Mads\Desktop\test\test.cpp|20|undefined reference to `sf::Window::display()'|
C:\Users\Mads\Desktop\test\test.cpp|9|undefined reference to `sf::Window::isOpen() const'|
C:\Users\Mads\Desktop\test\test.cpp|23|undefined reference to `sf::RenderWindow::~RenderWindow()'|
C:\Users\Mads\Desktop\test\test.cpp|23|undefined reference to `sf::RenderWindow::~RenderWindow()'|
obj\Debug\test.o||In function `~CircleShape':|
C:\Users\Mads\Desktop\SFML-2.0\include\SFML\Graphics\CircleShape.hpp|42|undefined reference to `vtable for sf::CircleShape'|
C:\Users\Mads\Desktop\SFML-2.0\include\SFML\Graphics\CircleShape.hpp|42|undefined reference to `vtable for sf::CircleShape'|
C:\Users\Mads\Desktop\SFML-2.0\include\SFML\Graphics\CircleShape.hpp|42|undefined reference to `sf::Shape::~Shape()'|
||=== Build finished: 20 errors, 0 warnings ===|

【问题讨论】:

  • 请在问题中输入代码。 1) 更容易阅读 2) 人们可能想要复制/粘贴它。但快速猜测,这是一个链接错误。未设置某些内容来查找包含所有这些符号的库。
  • 我建议您重新执行Creating and configuring a SFML project 下的步骤,并确保您正确执行了所有步骤,尤其是以The next step is to link your application to the SFML libraries (.a files) that your code will need. 开头的部分
  • 感谢您的回答。我会尝试重做一切,看看它是否有效
  • 看起来您没有在 code::blocks 中为项目的构建选项设置库文件。
  • 我确实设置了它。顺便说一句,我刚刚完成了所有操作,每次我在程序中执行某些操作时,它都会给我“环境错误”:在您为 GNU GCC 编译器配置的搜索路径中找不到编译器可执行文件

标签: c++ codeblocks sfml


【解决方案1】:

我遇到了同样的问题,我必须执行两个步骤才能使其正常工作。

1) 手动编译 SFML,而不是使用打包版本。

2) 在构建选项中将手动编译的版本添加到项目中。

在此之前,即使我按照文档中的说明指定了所有内容,我也经常收到这些错误。

【讨论】:

    【解决方案2】:

    你应该在你的 CB 项目文件中添加 *.cbp 这个:

    <Linker>
           <Add library="GL" />
    </Linker>
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2015-05-28
      • 2015-09-16
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-09-28
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多