您好,我尝试使用 xcode 从子目录导入 c++ 类,但收到一条错误消息:
Undefined symbols for architecture x86_64:
"Mother::Mother()", referenced from:
_main in main.o
"Mother::~Mother()", referenced from:
_main in main.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
我不明白,因为代码在终端上使用“clang++”与这个架构一起工作,可能是我错过了要导入我的文件的东西,或者可能是在设置中要做的事情?在屏幕截图中,我们看到所有文件都已导入。有关信息,模板文件或带有子目录的函数没有问题,只有将类放在子目录中,当类文件位于根目录时,这也是有效的。我希望这很清楚,如果任何机构对我有解决方案或帮助,那就太好了。
祝你有美好的一天。
我的配置:OSX 10.14.8 / Xcode 11.3.1
这里有一个简单的代码来重现:
main.c
#include <iostream>
#include "other/Mother.hpp"
int main(int argc, const char * argv[]) {
Mother Mother;
return 0;
}
Mother.hpp
#ifndef MOTHER_H
# define MOTHER_H
#include <iostream>
#include <string>
class Mother {
public:
Mother();
~Mother();
};
#endif
mother.cpp
#include "./Mother.hpp"
Mother::Mother() {
return;
}
Mother::~Mother() {
return;
}

