gpt4 book ai didi

c++ - 找不到链接库的符号

转载 作者:行者123 更新时间:2023-11-30 01:30:30 31 4
gpt4 key购买 nike

我正在编写一个简单的游戏引擎,并且我有 EntityComponent.h 文件:

#ifndef Psycho2D_Core_EntityComponent_
#define Psycho2D_Core_EntityComponent_

#include <string>

namespace psycho2d{

class EntityComponent{

private:
std::string m_name;

public:
EntityComponent(const std::string &name);

virtual ~EntityComponent();

const std::string& getName() const;

virtual void initialize() = 0;

virtual void loadProperties() = 0;

virtual void update() = 0;

virtual void destroy() = 0;

};

}

#endif

以及相关的 EntityComponent.cpp 文件:

#include "EntityComponent.h"
#include <string>

psycho2d::EntityComponent::EntityComponent(const std::string &name){
this->m_name = name;
}

psycho2d::EntityComponent::~EntityComponent(){}

inline const std::string& psycho2d::EntityComponent::getName() const{
return this->m_name;
}

这两个文件是框架的一部分(我在 Mac 上工作)。他们编译得很好。问题是当我编写一个使用该库的可执行文件时。我已经创建了一个 EntityComponent 的子类,它可以编译。但是,如果我调用 getName() 函数,链接器会告诉我:

"psycho2d::EntityComponent::getName() const", referenced from:
_main in main.o
Symbol(s) not found
Collect2: ld returned 1 exit status

我能做什么?谢谢。

最佳答案

如果要从多个 .cpp 文件中引用它,请将内联函数的代码放在头文件中。

引用 here .

关于c++ - 找不到链接库的符号,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4391202/

31 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com