【问题标题】:Unresolved External Symbol when using sf::Text and sf::Font [duplicate]使用 sf::Text 和 sf::Font 时未解析的外部符号 [重复]
【发布时间】:2013-01-21 23:14:36
【问题描述】:

我正在使用 sfml 2.0 创建一个文本类,当我尝试构建时遇到链接器错误。这是错误:

Error   1   error LNK2019: unresolved external symbol "__declspec(dllimport) public: static class sf::Font const & __cdecl sf::Font::getDefaultFont(void)" (__imp_?getDefaultFont@Font@sf@@SAAEBV12@XZ) referenced in function "public: void __cdecl Text::create(class sf::RenderWindow &,char *,char *,float,float,unsigned int,enum style,int,int,int)" (?create@Text@@QEAAXAEAVRenderWindow@sf@@PEAD1MMIW4style@@HHH@Z) C:\Facepunch Pacman Project\Faceman\Text.obj    Faceman

这里是 text.h:

#ifndef TE_TEXT
#define TE_TEXT

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

enum style { bold, italic, underlined };

class Text {

    public: 
        void create(sf::RenderWindow &window,
                    char* string, 
                    char* fontpath, 
                    float positionx, 
                    float positiony,
                    unsigned int size,
                    style textstyle,
                    int red, 
                    int green, 
                    int blue);

        void setString();
        void setFont();
        void setPosition();
        void setSize();
        void setColor(int red, int green, int blue);

        Text operator==(Text t);
        Text operator!=(Text t);

        sf::Rect<int> textrect;

        void setRect();

    private:
        char* getString();
        char* getFont();
        float getPosition();    
        unsigned int getSize();
        sf::Vector3i getColor();

        sf::IntRect getRect();
};

#endif

Text.cpp(未完成):

#include <Source/Text/Text.h>

void Text::create(sf::RenderWindow &window, char* string, char* fontpath, float positionx, float positiony, unsigned int size, 
                    style textstyle, int red, int green, int blue) {

    sf::Font font;
    font.loadFromFile(fontpath);

    sf::Text text(string);
    text.setFont(font);

    text.setCharacterSize(size);

    text.setPosition(positionx, positiony);

    sf::Color color(red, green, blue);
    text.setColor(color);

    switch (textstyle)
    {
        case bold:
        {
            text.setStyle(sf::Text::Bold);
            break;
        }

        case italic:
        {
            text.setStyle(sf::Text::Italic);
            break;
        }

        case underlined:
        {
            text.setStyle(sf::Text::Underlined);
            break;
        }
    }

    window.draw(text);
}

显示主菜单功能(这不是新的,我之前一直在使用它,没有任何问题)

Menu::MenuResult Menu::showMMenu(sf::RenderWindow &window) {

    sf::Texture texture;
    texture.loadFromFile("Source/Images/MenuBG.png");

    sf::Sprite MMenuSprite;
    MMenuSprite.setTexture(texture);

    Text playText;

    MenuItem playButton;
    playButton.buttonrect.top = 283;
    playButton.buttonrect.height = 130;
    playButton.buttonrect.left = 0;
    playButton.buttonrect.width = WINDOW_WIDTH;
    playButton.action = Play;

    MenuItem optionsButton;
    optionsButton.buttonrect.top = 414;
    optionsButton.buttonrect.height = 130;
    optionsButton.buttonrect.left = 0;
    optionsButton.buttonrect.width = WINDOW_WIDTH;
    optionsButton.action = Options;

    MenuItem exitButton;
    exitButton.buttonrect.top = 549;
    exitButton.buttonrect.height = 130;
    exitButton.buttonrect.left = 0;
    exitButton.buttonrect.width = WINDOW_WIDTH;
    exitButton.action = Exit;

    menuItems.push_back(playButton);
    menuItems.push_back(optionsButton);
    menuItems.push_back(exitButton);

    window.draw(MMenuSprite);
    playText.create(window, "start", "Source/Text/Fonts/BOOKOS.ttf", 514, 352, 65, bold, 0, 0, 0);
    window.display();

    return getMenuResponse(window);
}

我可能没有正确获取字体文件路径,因为 getDefaultFont 是在未指定字体时。

【问题讨论】:

  • 这堂课之前编译得很好,我正在链接正确的库。

标签: c++ text sfml


【解决方案1】:

您的头文件似乎与您的二进制文件不同步。该功能在 6 个月前被删除。

https://github.com/LaurentGomila/SFML/commit/a0c1f5f50f5e7ab52bd4b11296ffea1735b3b595

【讨论】:

  • 我不明白? sfml 2.0 文档仍然有这个类。
  • 请帮助 :( 我需要继续工作
  • @Tetramputechture:你从哪里下载 SFML?什么链接,具体是什么时候,什么时候?
猜你喜欢
  • 1970-01-01
  • 2010-11-12
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2020-08-21
  • 2018-08-27
  • 1970-01-01
相关资源
最近更新 更多