【问题标题】:include class file c++ from subdirectory in Xcode在 Xcode 的子目录中包含类文件 c++
【发布时间】:2020-10-15 16:04:50
【问题描述】:

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

【问题讨论】:

  • 我不知道 XCode,但我假设有一些“项目”文件列出了所有要编译的文件。确保Mother.cppmain.cpp 一起列出。
  • @Yksisarvinen 是的,我添加了文件,我使用模板和函数进行了测试,这很有效。这只发生在课堂上。当这个在子目录中时。

标签: c++ xcode include undefined-reference


【解决方案1】:

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

当文件夹与文件一起导入时,需要添加构建阶段首选项

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2021-01-07
    • 1970-01-01
    • 1970-01-01
    • 2013-05-14
    • 1970-01-01
    • 2021-12-29
    • 2017-11-28
    相关资源
    最近更新 更多