Xcode 错误"not found for architecture" 。尝试不使用库的基本C++

Xcode error "not found for architecture". trying basic C++ w/o libraries

本文关键字:C++ found not 错误 for architecture Xcode      更新时间:2023-10-16

我看到了很多关于这个"not found for architecture"的错误,但我还没有从阅读其他一些帖子中找到解决方案…(在我看来,他们大多数都专注于库链接,但我不认为我在使用任何库…)

我正在尝试做非常基本的c++东西,基本上只是传递一个对象到另一个类中的另一个函数。我是c++的初学者,主要来自Java,所以我甚至不完全确定是我写错了代码还是IDE的问题…

我的代码:

class One{
public:
    One();
    int value;
};
One::One(){
    value = 5;
}

class Two{
public:
    Two();
    One one;
    int doSomething(One* oneArgument);
    int somethingThatCallsDoSomething();
};
int Two::doSomething(One *oneArgument){
    return oneArgument->value;
}
int Two::somethingThatCallsDoSomething(){
    doSomething(&one);
    return 0;
}

int main(){
    Two two;
    return two.somethingThatCallsDoSomething();
}

我的错误是,我得到一个'构建失败'与两个错误:

架构x86_64的未定义符号:"Two::Two()",引用自:_main in main. 0没有找到架构x86_64的Ld:符号Clang:错误:链接器命令失败,退出代码为1(使用-v查看调用)

这是上面的附加文本(我不知道它是关于什么的…):

Ld/Users/Nafty/Library/Developer/Xcode/DerivedData/attempt_for_even_simpler_version_of_issue-gjurwihlodxqbjgukkxvnrjxcmti/Build/Products/Debug/try 更 简单 版本 issue。app/Contents/MacOS/attempt for 甚至 简单 版本 issue normal x86_64cd"/Users/Nafty/Documents/Philosophy/experiment 1 with Xcode/SDL2.0 w/attempt for even simple version of issue"出口MACOSX_DEPLOYMENT_TARGET = 10.9/应用程序/xcode/内容/开发/工具链/XcodeDefault。xctoolchain/usr/bin/clang++ -arch x86_64 -isysroot/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/sdk/MacOSX10.9。sdk -L/Users/Nafty/Library/Developer/Xcode/DerivedData/attempt_for_even_simpler_version_of_issue-gjurwihlodxqbjgukkxvnrjxcmti/Build/Products/Debug -L/opt/local/lib -L/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/sdk/MacOSX10.9。sdk/usr/lib -F/Users/Nafty/Library/Developer/Xcode/DerivedData/attempt_for_even_simpler_version_of_issue-gjurwihlodxqbjgukkxvnrjxcmti/Build/Products/Debug -F/Library/Frameworks -filelist/Users/Nafty/Library/Developer/Xcode/DerivedData/attempt_for_even_simpler_version_of_issue-gjurwihlodxqbjgukkxvnrjxcmti/Build/Intermediates/尝试 更 简单 版本 issue。构建/调试/尝试 更 简单 版本 问题。build/Objects-normal/x86_64/attempt for even version of issueLinkFileList -mmacosx-version-min=10.9 -framework cocoa -framework SDL2 -stdlib=libc++ -Xlinker -dependency_info -Xlinker/Users/Nafty/Library/Developer/Xcode/DerivedData/attempt_for_even_simpler_version_of_issue-gjurwihlodxqbjgukkxvnrjxcmti/Build/Intermediates/attempt for 更 简单版本 issue构建/调试/尝试 更 简单 版本 问题。- 0/Users/Nafty/Library/Developer/Xcode/DerivedData/attempt_for_even_simpler_version_of_issue-gjurwihlodxqbjgukkxvnrjxcmti/build/Products/Debug/attempt for even simple version of issue. datapp/Contents/MacOS/attempt for even version of issue

我从2012年11月开始在Macbook Pro视网膜显示器13"上运行Xcode 5.1.1

这个问题是非常令人沮丧的b/c我甚至不能通过基本的编程的东西进步…

非常感谢你的帮助!

您省略了类2默认构造函数。您可以将它添加到类定义

class Two{
public:
    Two() {}
    One one;
    int doSomething(One* oneArgument);
    int somethingThatCallsDoSomething();
};

或其他地方(像你的其他方法)

Two::Two(){
   //Some constructor code here
}