【问题标题】:QTCreator + SFML on Yosemite Undefined symbols for architecture x86_64QTCreator + SFML on Yosemite 架构 x86_64 的未定义符号
【发布时间】:2014-11-05 01:29:32
【问题描述】:

我正在尝试在 Yosemite 上配置 QTCreator 和 SFML,已经遇到了一个相当令人不快的问题,最低版本设置为 OS X 10.6(现在设置为 OS X 10.9),现在我遇到了“问题”架构 x86_64' 的未定义符号,这是 QTCreator 的应用程序输出:

Undefined symbols for architecture x86_64:
  "PlayMapAI::m_PlayMapAI", referenced from:
      PlayMapAI::instance() in MenuState.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
make: *** [framework] Error 1
23:23:14: The process "/usr/bin/make" exited with code 2.
Error while building/deploying project framework (kit: Desktop Qt 5.3 clang 64bit)
When executing step "Make"

下面是它运行的选项:

/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang++ -c -pipe -std=c++11 -Wno-ignored-qualifiers -g -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.10.sdk -mmacosx-version-min=10.9 -Wall -W -fPIE  -I/Applications/QT/5.3/clang_64/mkspecs/macx-clang -I../qtcreator -I../../include -I../../include/tinyxml -I../../include/tmxloader -I/usr/local/include -I/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.10.sdk/System/Library/Frameworks/OpenGL.framework/Versions/A/Headers -I/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.10.sdk/System/Library/Frameworks/AGL.framework/Headers -I. -o PlayState.o ../../source/PlayState.cpp

有什么建议吗?

-- 更新

这是 PlayMapAI.h 文件(没有任何 .cpp 文件):

#ifndef PLAY_MAPAI_H_
#define PLAY_MAPAI_H_

#include <list>
#include <string>
#include "GameState.h"
#include "Sprite.h"
#include "InputManager.h"
#include <MapLoader.h>

struct Kinematic
{
    cgf::Sprite* sprite;
    sf::Vector3f pos;
    sf::Vector3f vel;
    sf::Vector3f heading;
    float maxForce;
    float maxSpeed;
    float maxTurnRate;
};

class PlayMapAI : public cgf::GameState
{
public:

    void init();
    void cleanup();

    void pause();
    void resume();

    void handleEvents(cgf::Game* game);
    void update(cgf::Game* game);
    void draw(cgf::Game* game);

    // Implement Singleton Pattern
    static PlayMapAI* instance()
    {
        return &m_PlayMapAI;
    }

protected:

    PlayMapAI() {}

private:

    static PlayMapAI m_PlayMapAI;

    int x, y;
    float speed; // player speed
    float zvel;
    cgf::Sprite player;
    cgf::Sprite ghost;

    sf::RenderWindow* screen;

    std::list<sf::Vector3f> trail;
    bool showTrails;

    Kinematic playerK, enemyK;
    cgf::InputManager* im;
    sf::Font font;
    sf::Text text;
    tmx::MapLoader* map;
    bool firstTime;

    bool checkCollision(uint8_t layer, cgf::Game* game, Kinematic& obj);
    void centerMapOnPlayer();
    sf::Uint16 getCellFromMap(uint8_t layernum, float x, float y);

    enum {
         CHASE_BEHAVIOR=0, ARRIVE_BEHAVIOR, PURSUIT_BEHAVIOR, FLEE_BEHAVIOR, EVADE_BEHAVIOR
    };

    const static std::string modes[];

    int steerMode;
    sf::Vector3f chase(Kinematic& vehicle, sf::Vector3f& target); // ir diretamente ao jogador
    sf::Vector3f arrive(Kinematic& vehicle, sf::Vector3f& target, float decel=0.2); // ir diretamente ao jogador
    sf::Vector3f pursuit(Kinematic& vehicle, Kinematic& target); // perseguir o jogador, prevendo a posição futura
    sf::Vector3f flee(Kinematic& vehicle, sf::Vector3f& target, float panicDistance=100);  // fugir do jogador
    sf::Vector3f evade(Kinematic& vehicle, Kinematic& target);
};

#endif

【问题讨论】:

标签: qt-creator sfml


【解决方案1】:

我怀疑PlayMapAI::m_PlayMapAI 是一个静态字段。这意味着您必须在翻译单元 (.cpp) 中定义它,可能是 PlayMapAI.cpp,如下所示:

Type PlayMapAI::m_PlayMapAI;

【讨论】:

  • 抱歉拖了这么久才回复,刚刚更新了 PlayMapAI 代码,显然不是这样的......当我调用 instance() 方法时它崩溃了。
  • 是的,就是这样。否则你仍然会有同样的编译错误。现在你面临另一个挑战。使用调试器,如果需要,打开一个新问题。
  • 其实我还是一样的编译错误,我不能在其他任何地方声明PlayMapAI::m_PlayMapAI;,因为它是私有的,并且是通过instance()访问的。很抱歉打扰你,你能给我任何其他的建议吗?
  • 在声明 instance 函数时是否忘记了 PlayMapAI::
  • 当我调用实例时,我这样做PlayMapAI::instance(),因为它是一个单例,至于在函数内部声明它就像这样static PlayMapAI* instance(),它返回m_PlayMapAI,这是一个私有和静态属性。如果您想看一下,我的问题中对此进行了描述,我刚刚更新了代码。
【解决方案2】:

如果您使用任何 c++ 11 功能,您的 .pro 文件中必须有 CONFIG += c++11。还要确保您的编译器具有正确版本的 SFML。还要确保 QT 是最新的。

【讨论】:

    猜你喜欢
    • 2014-09-21
    • 2014-10-15
    • 1970-01-01
    • 2014-08-07
    • 2012-07-20
    • 1970-01-01
    • 2015-08-23
    • 2014-05-27
    • 2017-07-06
    相关资源
    最近更新 更多