我能够运行单个文件程序但是当涉及多个文件时,它将无法运行。下面是简单的代码示例和错误。我已经尝试从默认的GNU GCC编译器更改为LLVM Clang但似乎都不起作用。
我已经安装了命令行工具和XCode,因为我被警告过你需要这样才能使代码块正常工作。
这是main.cpp,Sally.h和Sally.cpp文件:
#include <iostream>
#include "Sally.h"
using namespace std;
int main(){
Sally s;
return 0;
}
#ifndef SALLY_H
#define SALLY_H
class Sally
{
public:
Sally();
protected:
private:
};
#endif // SALLY_H
#include "Sally.h"
#include <iostream>
using namespace std;
Sally::Sally()
{
cout << "wuttup" << endl;
}
我得到的错误信息是:
-------------- Build: Debug in Test (compiler: GNU GCC Compiler)---------------
g++ -Wall -fexceptions -g -I -c /Users/shackletom/Desktop/Test/main.cpp -o obj/Debug/main.o
Undefined symbols for architecture x86_64:
"Sally::Sally()", referenced from:
_main in main-9bf1fd.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
编辑,道歉,这里是完整的构建日志:
Apple LLVM version 7.0.2 (clang-700.1.81)
Target: x86_64-apple-darwin15.3.0
Thread model: posix
"/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang" -cc1 -triple x86_64-apple-macosx10.11.0 -Wdeprecated-objc-isa-usage -Werror=deprecated-objc-isa-usage -emit-obj -mrelax-all -disable-free -disable-llvm-verifier -main-file-name main.cpp -mrelocation-model pic -pic-level 2 -mthread-model posix -mdisable-fp-elim -masm-verbose -munwind-tables -target-cpu core2 -target-linker-version 253.9 -v -dwarf-column-info -resource-dir /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../lib/clang/7.0.2 -stdlib=libc++ -fdeprecated-macro -fdebug-compilation-dir /Users/shackletom/Desktop/Test -ferror-limit 19 -fmessage-length 179 -stack-protector 1 -mstackrealign -fblocks -fobjc-runtime=macosx-10.11.0 -fencode-extended-block-signature -fcxx-exceptions -fexceptions -fmax-type-align=16 -fdiagnostics-show-option -fcolor-diagnostics -o /var/folders/yf/ky2mbh0x0b71x9gdz0g8sp940000gn/T/main-885784.o -x c++ main.cpp
clang -cc1 version 7.0.2 based upon LLVM 3.7.0svn default target x86_64-apple-darwin15.3.0
ignoring nonexistent directory "/usr/include/c++/v1"
ignoring nonexistent directory "/usr/local/include"
#include "..." search starts here:
#include <...> search starts here:
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../include/c++/v1
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../lib/clang/7.0.2/include
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include
/usr/include
/System/Library/Frameworks (framework directory)
/Library/Frameworks (framework directory)
End of search list.
"/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/ld" -demangle -dynamic -arch x86_64 -macosx_version_min 10.11.0 -o test /var/folders/yf/ky2mbh0x0b71x9gdz0g8sp940000gn/T/main-885784.o -lc++ -lSystem /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../lib/clang/7.0.2/lib/darwin/libclang_rt.osx.a
Undefined symbols for architecture x86_64:
"Sally::Sally()", referenced from:
_main in main-885784.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
事实证明,在创建其他类时,我通过确保&#34;添加项目的路径来解决这个问题。根据文件政策,未经批准。