0

您好,我尝试使用 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;
}

在此处输入图像描述

4

1 回答 1

0

在 Open FrameWork 论坛中,解决方案给出了:https ://forum.openframeworks.cc/t/import-class-from-directory/35650/6

当文件夹与文件一起导入时,需要添加构建阶段首选项 在此处输入图像描述

于 2020-06-26T08:58:27.293 回答