我下載了gtest 1.6,並編譯它與鏗鏘++。gtest:未定義的符號體系結構x86_64錯誤與鏗鏘++和std ::向量
- 出口CC =的/ usr/bin中/鐺
- 出口CXX =的/ usr/bin中/鐺++
- 配置
- 使
我得到了libgtest.a,和我將其複製到/usr/local/lib/libgtest_clang.a
。當我使用簡單的C++代碼進行測試時,一切正常,但是,當我嘗試在測試代碼中使用向量時,我在構建過程中收到了這些錯誤消息。編譯工作正常。
Undefined symbols for architecture x86_64:
"std::basic_string<wchar_t, std::char_traits<wchar_t>, std::allocator<wchar_t> >::find(wchar_t const*, unsigned long, unsigned long) const", referenced from:
testing::AssertionResult testing::(anonymous namespace)::IsSubstringImpl<std::basic_string<wchar_t, std::char_traits<wchar_t>, std::allocator<wchar_t> > >(bool, char const*, char const*, std::basic_string<wchar_t, std::char_traits<wchar_t>, std::allocator<wchar_t> > const&, std::basic_string<wchar_t, std::char_traits<wchar_t>, std::allocator<wchar_t> > const&) in libgtest_clang.a(gtest-all.o)
...
這是我用於構建的命令行。
clang++ -DGTEST_USE_OWN_TR1_TUPLE=1 -std=c++11 -stdlib=libc++ main.cpp test_a.cc \
-L/usr/local/lib -I. -lgtest_clang -o t
這是測試代碼和待測試代碼。
#include <limits.h>
#include <time.h>
#include <gtest/gtest.h>
#include <list>
#include <vector>
#include <string>
#include "a.h"
using namespace std;
class QuickTest : public testing::Test {
protected:
virtual void SetUp() {
}
virtual void TearDown() {
}
};
class ErrorTest : public QuickTest {
protected:
virtual void SetUp() {
QuickTest::SetUp();
}
virtual void TearDown() {
QuickTest::TearDown();
}
};
TEST_F(ErrorTest, catchMessage2) {
vector<int> h {1,2,3,4,5};
for (auto& i : h) {
A* a = new A(i);
EXPECT_TRUE(a->get() == i);
delete a;
}
}
class A
{
int x;
public:
A(int x) : x(x) {}
void set(int x) {this->x = x;}
int get() {return x;}
};