I installed Google Test according to this How to properly setup googleTest on OS X aside from XCode. So, lib files ended up in /usr/lib/
.
But I was unable to compile with command
clang++ -I/usr/include -L/usr/lib t.cpp -lgtest
since I have received
ld: library not found for -lgtest
I have found this post ld library path not working under OS X 10.9, so I copied the libraries to another location: /opt/local/lib
. Now I am able to compile my code using
clang++ -I/opt/local/include -L/opt/local/lib/ t.cpp -lgtest
However, I can not remove them from /usr/lib
. If I do, I can not run the compiled program:
dyld: Library not loaded: /usr/local/lib/libgtest.0.dylib
Referenced from: /path_to_code/./a.out
Reason: image not found
Trace/BPT trap: 5
Maybe this is only some setting in my OS?
After being able to compile from command line, I tried from Qt Creator. I added to the project file
INCLUDEPATH += /opt/local/include
LIBS += -L/opt/local/lib -L/usr/lib -lgtest
but I have unresolved symbols:
Undefined symbols for architecture x86_64:
"testing::internal::EqFailure(char const*, char const*, std::string const&, std::string const&, bool)", referenced from:
testing::AssertionResult testing::internal::CmpHelperEQ<int, int>(char const*, char const*, int const&, int const&) in main.o
"std::string::c_str() const", referenced from:
testing::AssertionResult::message() const in main.o
"std::basic_stringstream<char, std::char_traits<char>, std::allocator<char> >::str() const", referenced from:
std::string testing::PrintToString<int>(int const&) in main.o
"std::ostream::operator<<(int)", referenced from:
void testing_internal::DefaultPrintNonContainerTo<int>(int const&, std::ostream*) in main.o
"std::basic_string<char, std::char_traits<char>, std::allocator<char> >::~basic_string()", referenced from:
testing::AssertionResult testing::internal::CmpHelperEQ<int, int>(char const*, char const*, int const&, int const&) in main.o
testing::internal::scoped_ptr<std::string>::reset(std::string*) in main.o
"std::basic_stringstream<char, std::char_traits<char>, std::allocator<char> >::basic_stringstream(std::_Ios_Openmode)", referenced from:
std::string testing::PrintToString<int>(int const&) in main.o
"std::basic_stringstream<char, std::char_traits<char>, std::allocator<char> >::~basic_stringstream()", referenced from:
std::string testing::PrintToString<int>(int const&) in main.o
"std::ios_base::Init::Init()", referenced from:
___cxx_global_var_init in main.o
"std::ios_base::Init::~Init()", referenced from:
___cxx_global_var_init 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)
make: *** [ut1] Error 1
22:52:06: The process "/usr/bin/make" exited with code 2.
Error while building/deploying project ut1 (kit: Desktop Qt 5.3 clang 64bit)
When executing step "Make"
Can somebody explain me what is happening there?