Clang linking error on Mac OSX - c++

I have a very basic C++ program which I cannot compile using g++ on Mac OSX 10.9.3.
Main.cpp
#include "MyClass.hpp"
int main() {
MyClass::MyClass obj = MyClass::MyClass();
return 0;
}
MyClass.hpp
class MyClass {
public:
MyClass();
void method();
private:
};
MyClass.cpp
#include "MyClass.hpp"
using namespace MyClass;
MyClass() {
};
void method() {
};
To compile it I use g++
g++ main.cpp -o out
Here is what I get as a result :
Undefined symbols for architecture x86_64:
"MyClass::MyClass()", referenced from:
_main in main-2750ac.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
So I then run g++ main.cpp -o out -v and get this :
Apple LLVM version 5.1 (clang-503.0.40) (based on LLVM 3.4svn)
Target: x86_64-apple-darwin13.2.0
Thread model: posix
"/Applications/Xcode.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 236.3 -v -resource-dir /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../lib/clang/5.1 -stdlib=libc++ -fdeprecated-macro -fdebug-compilation-dir /Users/stan/Documents/Info/Ateliers C++/Ateliers/Drawing -ferror-limit 19 -fmessage-length 120 -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/58/ch14y2yx05v7vy1yvrsmy_3m0000gn/T/main-4d20fb.o -x c++ issue/main.cpp
clang -cc1 version 5.1 based upon LLVM 3.4svn default target x86_64-apple-darwin13.2.0
ignoring nonexistent directory "/usr/include/c++/v1"
#include "..." search starts here:
#include <...> search starts here:
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../lib/c++/v1
/usr/local/include
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../lib/clang/5.1/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.9.0 -o out /var/folders/58/ch14y2yx05v7vy1yvrsmy_3m0000gn/T/main-4d20fb.o -lc++ -lSystem /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../lib/clang/5.1/lib/darwin/libclang_rt.osx.a
Undefined symbols for architecture x86_64:
"MyClass::MyClass()", referenced from:
_main in main-4d20fb.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
I get stuck here.

You don't compile MyClass.cpp. Try this:
g++ main.cpp MyClass.cpp -o out

Related

After update of llvm cannot find <filesystem> references on macOS with hombrew

I have updated my llvm installation, such that I now use Clang8.
After that I keep getting this error:
Undefined symbols for architecture x86_64:
"std::__1::__fs::filesystem::__status(std::__1::__fs::filesystem::path const&, std::__1::error_code*)", referenced from:
std::__1::__fs::filesystem::is_directory(std::__1::__fs::filesystem::path const&) in main-de2419.o
ld: symbol(s) not found for architecture x86_64
clang-8: error: linker command failed with exit code 1 (use -v to see invocation)
So it can find the header for filesystem but not the lib (as I understand). I have this test program:
#include <filesystem>
#include <iostream>
int main(void)
{
auto isDir = std::filesystem::is_directory("./main.cpp");
std::cout << isDir << std::endl;
return 0;
}
And I compile it this way clang++ -std=c++17 main.cpp. If with -v the output is:
clang version 8.0.0 (tags/RELEASE_800/final)
Target: x86_64-apple-darwin18.2.0
Thread model: posix
InstalledDir: /usr/local/opt/llvm/bin
"/usr/local/Cellar/llvm/8.0.0/bin/clang-8" -cc1 -triple x86_64-apple-macosx10.14.0 -Wdeprecated-objc-isa-usage -Werror=deprecated-objc-isa-usage -emit-obj -mrelax-all -disable-free -disable-llvm-verifier -discard-value-names -main-file-name main.cpp -mrelocation-model pic -pic-level 2 -mthread-model posix -mdisable-fp-elim -masm-verbose -munwind-tables -target-cpu penryn -dwarf-column-info -debugger-tuning=lldb -ggnu-pubnames -target-linker-version 409.12 -v -resource-dir /usr/local/Cellar/llvm/8.0.0/lib/clang/8.0.0 -stdlib=libc++ -internal-isystem /usr/local/opt/llvm/bin/../include/c++/v1 -std=c++17 -fdeprecated-macro -fdebug-compilation-dir /Users/larsnielsen/Desktop/test/test_filesystem -ferror-limit 19 -fmessage-length 160 -stack-protector 1 -fblocks -fencode-extended-block-signature -fregister-global-dtors-with-atexit -fobjc-runtime=macosx-10.14.0 -fcxx-exceptions -fexceptions -fmax-type-align=16 -fdiagnostics-show-option -fcolor-diagnostics -o /var/folders/df/wm8q24k53dz09jn4q35122bw0000gn/T/main-2be1ed.o -x c++ main.cpp
clang -cc1 version 8.0.0 based upon LLVM 8.0.0 default target x86_64-apple-darwin18.2.0
ignoring nonexistent directory "/usr/include/c++/v1"
#include "..." search starts here:
#include <...> search starts here:
/usr/local/opt/llvm/bin/../include/c++/v1
/usr/local/include
/usr/local/Cellar/llvm/8.0.0/lib/clang/8.0.0/include
/usr/include
/System/Library/Frameworks (framework directory)
/Library/Frameworks (framework directory)
End of search list.
"/usr/bin/ld" -demangle -lto_library /usr/local/Cellar/llvm/8.0.0/lib/libLTO.dylib -no_deduplicate -dynamic -arch x86_64 -macosx_version_min 10.14.0 -o a.out /var/folders/df/wm8q24k53dz09jn4q35122bw0000gn/T/main-2be1ed.o -lc++ -lSystem /usr/local/Cellar/llvm/8.0.0/lib/clang/8.0.0/lib/darwin/libclang_rt.osx.a
Undefined symbols for architecture x86_64:
"std::__1::__fs::filesystem::__status(std::__1::__fs::filesystem::path const&, std::__1::error_code*)", referenced from:
std::__1::__fs::filesystem::is_directory(std::__1::__fs::filesystem::path const&) in main-2be1ed.o
ld: symbol(s) not found for architecture x86_64
clang-8: error: linker command failed with exit code 1 (use -v to see invocation)
I have trieded a few solution options, without success:
I have changed to use <experimental/filesystem>
I have tried to link stdc++fs and c++fs
I have tried to export LDFLAGS="-L/usr/local/opt/llvm/lib" and CPPFLAGS="-I/usr/local/opt/llvm/include"
And I have added this to my .bash_profile export PATH="/usr/local/opt/llvm/bin:$PATH"
I have update LLVM on both my Fedora and macOS, and only the Mac has the issue. I updated using homebrew on macOS.

C++ Codeblocks Compilation Issue with multiple files OSX 10.11

I'm able to run single file programs but when it comes to multiple files, it will not run. Below is the simple code example and error. I have already tried changing to LLVM Clang from the default GNU GCC compiler but neither seem to work.
I've also already installed Command Line Tools and XCode as I was warned you would need this to have codeblocks working correctly.
This is the main.cpp, Sally.h and Sally.cpp file:
#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;
}
The error message I'm getting is this:
-------------- 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)
Edit, apologies, here's the full build log:
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)
Update:
Turns out that while creating the other classes I fixed this problem by making sure "Add paths to project" under File Policy was unticked.

Why won’t this simple C++ code compile with clang++? [duplicate]

This question already has answers here:
What is an undefined reference/unresolved external symbol error and how do I fix it?
(39 answers)
Closed 8 years ago.
Here is a very simple C++ program.
// test.h
class Test {
public:
Test();
};
// test.cpp
#include "test.h"
Test::Test()
{
// do something
}
// main.cpp
#include "test.h"
int main() {
Test t;
return 0;
}
I am trying to compile this using clang++ on OSX using this command line and I get this error:
[test]$ clang++ main.cpp -o main
Undefined symbols for architecture x86_64:
"Test::Test()", referenced from:
_main in main-017149.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
And here is the compilation with the -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 for architecture x86_64:
"Test::Test()", referenced from:
_main in main-d17898.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
What am I doing wrong?
main.cpp includes test.h; it does not include test.cpp. You can compile and link them at the same time by specifying them both as input:
[test]$ clang++ main.cpp test.cpp -o main
You missed other cpp file:
clang++ main.cpp test.cpp -o main

Undefined symbols for architecture x86_64 in clang

I've checked more or less all the answers to this kind of problem wich seems quite usual when compiling with the new llvm package but I couldn't find any solution.
MacBook-Air-di-Manfredo:SINGLE_TETRAMER manfredo$ clang++ -v -Wall -O3 -g -fpic -c -lm grbyinsertion.cpp -I/Users/manfredo/Desktop/tesi/codice_tesi/oxDNA/src/Observables
Apple LLVM version 5.1 (clang-503.0.40) (based on LLVM 3.4svn)
Target: x86_64-apple-darwin13.1.0
Thread model: posix
clang: warning: -lm: 'linker' input unused
"/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang" -cc1 -triple x86_64-apple-macosx10.9.0 -emit-obj -disable-free -disable-llvm-verifier -main-file-name grbyinsertion.cpp -mrelocation-model pic -pic-level 2 -mdisable-fp-elim -masm-verbose -munwind-tables -target-cpu core2 -target-linker-version 236.3 -v -gdwarf-2 -coverage-file /Users/manfredo/Desktop/tesi/codice_tesi/SINGLE_TETRAMER/grbyinsertion.o -resource-dir /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../lib/clang/5.1 -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.9.sdk -I /Users/manfredo/Desktop/tesi/codice_tesi/oxDNA/src/Observables -stdlib=libc++ -O3 -Wall -fdeprecated-macro -fdebug-compilation-dir /Users/manfredo/Desktop/tesi/codice_tesi/SINGLE_TETRAMER -ferror-limit 19 -fmessage-length 121 -stack-protector 1 -mstackrealign -fblocks -fobjc-runtime=macosx-10.9.0 -fencode-extended-block-signature -fcxx-exceptions -fexceptions -fdiagnostics-show-option -fcolor-diagnostics -vectorize-loops -vectorize-slp -o grbyinsertion.o -x c++ grbyinsertion.cpp
clang -cc1 version 5.1 based upon LLVM 3.4svn default target x86_64-apple-darwin13.1.0
ignoring nonexistent directory "/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.9.sdk/usr/include/c++/v1"
ignoring nonexistent directory "/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.9.sdk/usr/local/include"
ignoring nonexistent directory "/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.9.sdk/Library/Frameworks"
#include "..." search starts here:
#include <...> search starts here:
/Users/manfredo/Desktop/tesi/codice_tesi/oxDNA/src/Observables
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../lib/c++/v1
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../lib/clang/5.1/include
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include
/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.9.sdk/usr/include
/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.9.sdk/System/Library/Frameworks (framework directory)
End of search list.
grbyinsertion.cpp:63:9: warning: unused variable 'box_side' [-Wunused-variable]
number box_side = *this->_config_info.box_side;
^
grbyinsertion.cpp:156:16: note: in instantiation of member function 'grbyinsertion<float>::init' requested here
template class grbyinsertion<float>;
^
grbyinsertion.cpp:63:9: warning: unused variable 'box_side' [-Wunused-variable]
number box_side = *this->_config_info.box_side;
^
grbyinsertion.cpp:157:16: note: in instantiation of member function 'grbyinsertion<double>::init' requested here
template class grbyinsertion<double>;
^
2 warnings generated.
MacBook-Air-di-Manfredo:SINGLE_TETRAMER manfredo$ clang++ -v -shared -o grbyinsertion.so grbyinsertion.o -g2
Apple LLVM version 5.1 (clang-503.0.40) (based on LLVM 3.4svn)
Target: x86_64-apple-darwin13.1.0
Thread model: posix
"/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/ld" -demangle -dynamic -dylib -arch x86_64 -macosx_version_min 10.9.0 -syslibroot /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.9.sdk -o grbyinsertion.so grbyinsertion.o -lc++ -lSystem /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../lib/clang/5.1/lib/darwin/libclang_rt.osx.a
Undefined symbols for architecture x86_64:
"_getInputFloat", referenced from:
grbyinsertion<float>::get_settings(input_file&, input_file&) in grbyinsertion.o
grbyinsertion<double>::get_settings(input_file&, input_file&) in grbyinsertion.o
"_getInputInt", referenced from:
grbyinsertion<float>::get_settings(input_file&, input_file&) in grbyinsertion.o
grbyinsertion<double>::get_settings(input_file&, input_file&) in grbyinsertion.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
The function getinputfloat is defined in an header file like so:
int getInputFloat(input_file *inp, const char *skey, float *dest, int mandatory) {
int key = getInputKeyIndex(inp, skey, mandatory);
if(key != KEY_NOT_FOUND) *dest = atof(inp->values[key]);
else return KEY_NOT_FOUND;
return KEY_FOUND;
}
and is called by my program like so:
template<typename number>
void grbyinsertion<number>::get_settings(input_file &my_inp, input_file &sim_inp) {
float tmp;
if(getInputFloat(&my_inp, "bin", &tmp, 0) == KEY_FOUND) _bin = tmp;
getInputInt(&my_inp, "insertions", &_insertions, 0);
getInputFloat(&sim_inp, "T", &tmp, 1);
_T = tmp;
if(getInputFloat(&my_inp, "gr_min", &tmp, 0) == KEY_FOUND) _min = tmp;
if(getInputFloat(&my_inp, "gr_max", &tmp, 0) == KEY_FOUND) _max = tmp;
}
I've actually noticed that the header file where the getinputfloat function is defined is a .c file while most (i thought all of them) of the other files are .cpp, could this be the problem?
My llvm version is the 3.5 and I've upgraded all ports installed (via macports). Thanks.

Compile error when including boost/thread.hpp

I'm trying to use threads in C++, using boost's thread library. Clang is giving me an error and I don't know how to interpret it. The file I'm trying to compile is about as minimal as it can get:
#include <iostream>
#include <boost/thread.hpp>
using namespace std;
int main() {
return 0;
}
Here's the transcript:
$ clang++ -std=c++11 -o 4.4 4.4.cpp -v
Apple clang version 4.1 (tags/Apple/clang-421.11.66) (based on LLVM 3.1svn)
Target: x86_64-apple-darwin12.2.1
Thread model: posix
"/usr/bin/clang" -cc1 -triple x86_64-apple-macosx10.8.0 -emit-obj -mrelax-all -disable-free -disable-llvm-verifier -main-file-name 4.4.cpp -pic-level 1 -mdisable-fp-elim -relaxed-aliasing -masm-verbose -munwind-tables -target-cpu core2 -target-linker-version 134.9 -v -resource-dir /usr/bin/../lib/clang/4.1 -fmodule-cache-path /var/folders/mt/k4dhhm7d7_7_q6drl3zkjj4r0000gn/T/clang-module-cache -std=c++11 -fdeprecated-macro -fdebug-compilation-dir /Users/thinkpad20/Documents/workspace/cpp/homework4 -ferror-limit 19 -fmessage-length 100 -stack-protector 1 -mstackrealign -fblocks -fobjc-runtime-has-arc -fobjc-runtime-has-weak -fobjc-dispatch-method=mixed -fobjc-default-synthesize-properties -fcxx-exceptions -fexceptions -fdiagnostics-show-option -fcolor-diagnostics -o /var/folders/mt/k4dhhm7d7_7_q6drl3zkjj4r0000gn/T/4-49j8fE.o -x c++ 4.4.cpp
clang -cc1 version 4.1 based upon LLVM 3.1svn default target x86_64-apple-darwin12.2.1
ignoring nonexistent directory "/usr/include/c++/4.2.1/i686-apple-darwin10/x86_64"
ignoring nonexistent directory "/usr/include/c++/4.0.0"
ignoring nonexistent directory "/usr/include/c++/4.0.0/i686-apple-darwin8/"
ignoring nonexistent directory "/usr/include/c++/4.0.0/backward"
ignoring nonexistent directory "/usr/local/include"
#include "..." search starts here:
#include <...> search starts here:
/usr/include/c++/4.2.1
/usr/include/c++/4.2.1/backward
/usr/bin/../lib/clang/4.1/include
/usr/include
/System/Library/Frameworks (framework directory)
/Library/Frameworks (framework directory)
End of search list.
"/usr/bin/ld" -demangle -dynamic -arch x86_64 -macosx_version_min 10.8.0 -o 4.4 /var/folders/mt/k4dhhm7d7_7_q6drl3zkjj4r0000gn/T/4-49j8fE.o -lstdc++ -lSystem /usr/bin/../lib/clang/4.1/lib/darwin/libclang_rt.osx.a
Undefined symbols for architecture x86_64:
"boost::system::system_category()", referenced from:
___cxx_global_var_init3 in 4-49j8fE.o
"boost::system::generic_category()", referenced from:
___cxx_global_var_init1 in 4-49j8fE.o
___cxx_global_var_init2 in 4-49j8fE.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
Any help is appreciated! :)
You need to tell clang which libraries to link against. In your case, this is boost_system (that's what the error message tells you) and (as soon as you actually get around to using some threading stuff in your program) boost_thread as well, so compile it like this:
clang++ -std=c++11 -o myapp myfile.cpp -lboost_system -lboost_thread