【发布时间】:2015-02-15 04:38:15
【问题描述】:
我根据这个How to properly setup googleTest on OS X aside from XCode安装了Google Test。因此,lib 文件最终以/usr/lib/ 结尾。
但是我无法用命令编译
clang++ -I/usr/include -L/usr/lib t.cpp -lgtest
因为我收到了
ld: library not found for -lgtest
我找到了这个帖子ld library path not working under OS X 10.9,所以我将这些库复制到另一个位置:/opt/local/lib。现在我可以使用
clang++ -I/opt/local/include -L/opt/local/lib/ t.cpp -lgtest
但是,我无法将它们从 /usr/lib 中删除。如果我这样做了,我将无法运行已编译的程序:
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
也许这只是我操作系统中的一些设置?
在能够从命令行编译后,我尝试从 Qt Creator 中进行编译。我添加到项目文件中
INCLUDEPATH += /opt/local/include
LIBS += -L/opt/local/lib -L/usr/lib -lgtest
但我有未解析的符号:
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"
谁能解释一下那里发生了什么?
【问题讨论】: