首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >使用sf::Text和sf::Font时无法解析的外部符号

使用sf::Text和sf::Font时无法解析的外部符号
EN

Stack Overflow用户
提问于 2013-01-22 07:14:37
回答 1查看 832关注 0票数 0

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

代码语言:javascript
复制
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:

代码语言:javascript
复制
#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 (未完成):

代码语言:javascript
复制
#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);
}

显示主菜单功能(这并不是什么新鲜事,我以前一直在使用它,没有任何问题)

代码语言:javascript
复制
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是正确的。

EN

回答 1

Stack Overflow用户

发布于 2013-01-22 07:48:27

看起来你的头文件和你的二进制文件不同步。该功能在6个月前被移除。

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

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/14448915

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档