osx - Why won’t this simple C++ code compile with clang++? -
this question has answer here:
here simple c++ program.
// test.h class test { public: test(); }; // test.cpp #include "test.h" test::test() { // } // main.cpp #include "test.h" int main() { test t; return 0; } i trying compile using clang++ on osx using command line , error:
[test]$ clang++ main.cpp -o main undefined symbols architecture x86_64: "test::test()", referenced from: _main in main-017149.o ld: symbol(s) not found architecture x86_64 clang: error: linker command failed exit code 1 (use -v see invocation)
and here compilation -v switch:
[test]$ clang++ main.cpp -o main -v apple llvm version 6.0 (clang-600.0.34.4) (based on llvm 3.5svn) target: x86_64-apple-darwin13.2.0 thread model: posix "/applications/xcode6-beta2.app/contents/developer/toolchains/xcodedefault.xctoolchain/usr/bin/clang" -cc1 -triple x86_64-apple-macosx10.9.0 -emit-obj -mrelax-all -disable-free -disable-llvm-verifier -main-file-name main.cpp -mrelocation-model pic -pic-level 2 -mdisable-fp-elim -masm-verbose -munwind-tables -target-cpu core2 -target-linker-version 241 -v -resource-dir /applications/xcode6-beta2.app/contents/developer/toolchains/xcodedefault.xctoolchain/usr/bin/../lib/clang/6.0 -stdlib=libc++ -fdeprecated-macro -fdebug-compilation-dir /users/ramin/projects/algorithm_examples/test -ferror-limit 19 -fmessage-length 139 -stack-protector 1 -mstackrealign -fblocks -fobjc-runtime=macosx-10.9.0 -fencode-extended-block-signature -fcxx-exceptions -fexceptions -fdiagnostics-show-option -fcolor-diagnostics -vectorize-slp -o /var/folders/z5/hyt30v7d7t7_w1xfpdgqp05w0000gn/t/main-d17898.o -x c++ main.cpp clang -cc1 version 6.0 based upon llvm 3.5svn default target x86_64-apple-darwin13.2.0 ignoring nonexistent directory "/usr/include/c++/v1" #include "..." search starts here: #include <...> search starts here: /applications/xcode6-beta2.app/contents/developer/toolchains/xcodedefault.xctoolchain/usr/bin/../include/c++/v1 /usr/local/include /applications/xcode6-beta2.app/contents/developer/toolchains/xcodedefault.xctoolchain/usr/bin/../lib/clang/6.0/include /applications/xcode6-beta2.app/contents/developer/toolchains/xcodedefault.xctoolchain/usr/include /usr/include /system/library/frameworks (framework directory) /library/frameworks (framework directory) end of search list. "/applications/xcode6-beta2.app/contents/developer/toolchains/xcodedefault.xctoolchain/usr/bin/ld" -demangle -dynamic -arch x86_64 -macosx_version_min 10.9.0 -o main /var/folders/z5/hyt30v7d7t7_w1xfpdgqp05w0000gn/t/main-d17898.o -lc++ -lsystem /applications/xcode6-beta2.app/contents/developer/toolchains/xcodedefault.xctoolchain/usr/bin/../lib/clang/6.0/lib/darwin/libclang_rt.osx.a undefined symbols architecture x86_64: "test::test()", referenced from: _main in main-d17898.o ld: symbol(s) not found architecture x86_64 clang: error: linker command failed exit code 1 (use -v see invocation) what doing wrong?
main.cpp includes test.h; not include test.cpp. can compile , link them @ same time specifying them both input:
[test]$ clang++ main.cpp test.cpp -o main
Comments
Post a Comment