【问题标题】:Font Error SFML字体错误 SFML
【发布时间】:2018-08-26 18:42:30
【问题描述】:

我正在尝试使用 SFML 制作游戏,目前正处于加载文本阶段。我正在使用 mingw 编译器来编译我的程序,但是当我编译它时,我得到了这个错误

对`_imp___ZN2sf4Font12loadFromFileERKNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEE'的未定义引用

字体文件与代码在同一文件夹中。

这是我的代码。

#include <SFML/Graphics.hpp>
#include <iostream>
int main()
{
   sf::RenderWindow Window(sf::VideoMode::getDesktopMode(),"Hello Window");
   sf::Font font;
   if(!font.loadFromFile("bit.ttf"))
   {
       std::cout << "No Work";
   }
   sf::Text text("hello", font);
   text.setCharacterSize(30);
   text.setStyle(sf::Text::Bold);
   text.setColor(sf::Color::Red);
    while(Window.isOpen())
    {

      sf::Event Event;
      while(Window.pollEvent(Event))
      {

          if(Event.type == sf::Event::Closed)
          {

              Window.close();
          }

      }

      // Declare and load a font


// Create a text

// Draw it
      Window.draw(text);
      Window.clear(sf::Color());
      Window.display();
    }
}

【问题讨论】:

  • 您没有链接到 sfml 库。它与您的字体无关。
  • 我该怎么做这基本上是我的问题

标签: c++ mingw sfml


【解决方案1】:

您有一个链接器错误。要解决此问题,您需要找到 SFML dll 并将它们粘贴到可执行文件夹中,或者将它们的路径添加到 PATH 环境变量中。有关如何执行此操作的信息,请参阅 this

接下来,您必须确保将正确的 .lib 文件添加到链接器输入中。可以在 here 找到有关如何在 Visual Studio 中执行此操作的信息。对于其他 IDE,您可以查看this 页面。

【讨论】:

  • 在 mingw 中,程序在字体被注释掉时编译,我已经添加了 SFML dll,这是我的编译语句。 g++ %file% -IC:\Development\SFML-2.3.1\include -LC:\Development\SFML-2.3.1\lib -lsfml-graphics -lsfml-window -lsfml-system -o %exe%
  • 我使用 Mingw 仅供参考,所以我没有 IDE
  • 我建议你买一个,比如 Visual Studio。这样链接库就变得容易多了,而且你有一个很好的编码环境。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2023-03-30
  • 1970-01-01
  • 2016-03-29
  • 2013-10-04
  • 2013-12-11
相关资源
最近更新 更多