基本C ++程序链接Xcode中的错误

时间:2017-02-25 16:06:49

标签: c++ xcode linker-errors

从Python转向C ++,并努力过渡到编译语言。我正在使用Xcode,但使用Netbeans时遇到了同样的问题。

我有一个非常简单的项目,名为" main.cpp"以下是:

#include <iostream>

class Planet {
    int radius, mass, grav_constant;

public:

    Planet(int radius, int mass, int grav_constant);
    int get_radius() { return radius; };
    void set_radius(int new_rad) { radius = new_rad; };

};



using namespace std;

int main()
{

    Planet x {1,2,3};

cout << x.get_radius();

    return 0;
};

我收到以下错误:

Showing Recent Errors Only
Check dependencies

CompileC /Users/thomastry/Library/Developer/Xcode/DerivedData/First-aumojcbhbilmlehavktorbosazht/Build/Intermediates/First.build/Debug/First.build/Objects-normal/x86_64/main.o First/main.cpp normal x86_64 c++ com.apple.compilers.llvm.clang.1_0.compiler
    cd "/Users/thomastry/Programming/My Xcode projects/Test/First"
    export LANG=en_US.US-ASCII
    /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang -x c++ -arch x86_64 -fmessage-length=0 -fdiagnostics-show-note-include-stack -fmacro-backtrace-limit=0 -std=gnu++1y -stdlib=libc++ -fmodules -gmodules -fmodules-cache-path=/Users/thomastry/Library/Developer/Xcode/DerivedData/ModuleCache -fmodules-prune-interval=86400 -fmodules-prune-after=345600 -fbuild-session-file=/Users/thomastry/Library/Developer/Xcode/DerivedData/ModuleCache/Session.modulevalidation -fmodules-validate-once-per-build-session -Wnon-modular-include-in-framework-module -Werror=non-modular-include-in-framework-module -Wno-trigraphs -fpascal-strings -O0 -fno-common -Wno-missing-field-initializers -Wno-missing-prototypes -Werror=return-type -Wdocumentation -Wunreachable-code -Werror=deprecated-objc-isa-usage -Werror=objc-root-class -Wno-non-virtual-dtor -Wno-overloaded-virtual -Wno-exit-time-destructors -Wno-missing-braces -Wparentheses -Wswitch -Wunused-function -Wno-unused-label -Wno-unused-parameter -Wunused-variable -Wunused-value -Wempty-body -Wconditional-uninitialized -Wno-unknown-pragmas -Wno-shadow -Wno-four-char-constants -Wno-conversion -Wconstant-conversion -Wint-conversion -Wbool-conversion -Wenum-conversion -Wshorten-64-to-32 -Wno-newline-eof -Wno-c++11-extensions -DDEBUG=1 -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.12.sdk -fasm-blocks -fstrict-aliasing -Wdeprecated-declarations -Winvalid-offsetof -mmacosx-version-min=10.12 -g -fvisibility-inlines-hidden -Wno-sign-conversion -Winfinite-recursion -Wmove -iquote /Users/thomastry/Library/Developer/Xcode/DerivedData/First-aumojcbhbilmlehavktorbosazht/Build/Intermediates/First.build/Debug/First.build/First-generated-files.hmap -I/Users/thomastry/Library/Developer/Xcode/DerivedData/First-aumojcbhbilmlehavktorbosazht/Build/Intermediates/First.build/Debug/First.build/First-own-target-headers.hmap -I/Users/thomastry/Library/Developer/Xcode/DerivedData/First-aumojcbhbilmlehavktorbosazht/Build/Intermediates/First.build/Debug/First.build/First-all-target-headers.hmap -iquote /Users/thomastry/Library/Developer/Xcode/DerivedData/First-aumojcbhbilmlehavktorbosazht/Build/Intermediates/First.build/Debug/First.build/First-project-headers.hmap -I/Users/thomastry/Library/Developer/Xcode/DerivedData/First-aumojcbhbilmlehavktorbosazht/Build/Products/Debug/include -I/Users/thomastry/Library/Developer/Xcode/DerivedData/First-aumojcbhbilmlehavktorbosazht/Build/Intermediates/First.build/Debug/First.build/DerivedSources/x86_64 -I/Users/thomastry/Library/Developer/Xcode/DerivedData/First-aumojcbhbilmlehavktorbosazht/Build/Intermediates/First.build/Debug/First.build/DerivedSources -F/Users/thomastry/Library/Developer/Xcode/DerivedData/First-aumojcbhbilmlehavktorbosazht/Build/Products/Debug -MMD -MT dependencies -MF /Users/thomastry/Library/Developer/Xcode/DerivedData/First-aumojcbhbilmlehavktorbosazht/Build/Intermediates/First.build/Debug/First.build/Objects-normal/x86_64/main.d --serialize-diagnostics /Users/thomastry/Library/Developer/Xcode/DerivedData/First-aumojcbhbilmlehavktorbosazht/Build/Intermediates/First.build/Debug/First.build/Objects-normal/x86_64/main.dia -c /Users/thomastry/Programming/My\ Xcode\ projects/Test/First/First/main.cpp -o /Users/thomastry/Library/Developer/Xcode/DerivedData/First-aumojcbhbilmlehavktorbosazht/Build/Intermediates/First.build/Debug/First.build/Objects-normal/x86_64/main.o

Ld /Users/thomastry/Library/Developer/Xcode/DerivedData/First-aumojcbhbilmlehavktorbosazht/Build/Products/Debug/First normal x86_64
    cd "/Users/thomastry/Programming/My Xcode projects/Test/First"
    export MACOSX_DEPLOYMENT_TARGET=10.12
    /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang++ -arch x86_64 -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.12.sdk -L/Users/thomastry/Library/Developer/Xcode/DerivedData/First-aumojcbhbilmlehavktorbosazht/Build/Products/Debug -F/Users/thomastry/Library/Developer/Xcode/DerivedData/First-aumojcbhbilmlehavktorbosazht/Build/Products/Debug -filelist /Users/thomastry/Library/Developer/Xcode/DerivedData/First-aumojcbhbilmlehavktorbosazht/Build/Intermediates/First.build/Debug/First.build/Objects-normal/x86_64/First.LinkFileList -mmacosx-version-min=10.12 -Xlinker -object_path_lto -Xlinker /Users/thomastry/Library/Developer/Xcode/DerivedData/First-aumojcbhbilmlehavktorbosazht/Build/Intermediates/First.build/Debug/First.build/Objects-normal/x86_64/First_lto.o -Xlinker -export_dynamic -Xlinker -no_deduplicate -stdlib=libc++ -Xlinker -dependency_info -Xlinker /Users/thomastry/Library/Developer/Xcode/DerivedData/First-aumojcbhbilmlehavktorbosazht/Build/Intermediates/First.build/Debug/First.build/Objects-normal/x86_64/First_dependency_info.dat -o /Users/thomastry/Library/Developer/Xcode/DerivedData/First-aumojcbhbilmlehavktorbosazht/Build/Products/Debug/First

Undefined symbols for architecture x86_64:
  "Planet::Planet(int, int, int)", 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)



Activity Log Complete    25/02/2017, 16:03

我尝试在&#34; Build Settings&#34;中更改各种架构设置。菜单,尝试更改链接器,但似乎没有任何区别。感谢任何建议。

汤姆

由@Biffen解决,未宣布Planet:

class Planet {
    int radius, mass, grav_constant;

public:

    Planet(int x, int y, int z) {
        radius = x;
        mass = y;
        grav_constant = z;

    };

    int get_radius() { return radius; };
    void set_radius(int new_rad) { radius = new_rad; };

};

0 个答案:

没有答案