0

我正在使用 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

文本.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 是在未指定字体时。

4

1 回答 1

0

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

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

于 2013-01-21T23:48:27.143 回答