2013-06-24 14 views
2

我下載了gtest 1.6,並編譯它與鏗鏘++。gtest:未定義的符號體系結構x86_64錯誤與鏗鏘++和std ::向量

  1. 出口CC =的/ usr/bin中/鐺
  2. 出口CXX =的/ usr/bin中/鐺++
  3. 配置
  4. 使

我得到了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;} 
}; 

回答

5

問題出在構建gtest時沒有提供相同的編譯器選項。

export CC=/usr/bin/clang 
export CXX=/usr/bin/clang++ 
./configure 'CXXFLAGS=-std=c++11 -stdlib=libc++ -DGTEST_USE_OWN_TR1_TUPLE=1' 
make 

gtest和源代碼的新版本後,一切工作正常。

0

只是幸運的提示,像我這樣的小白癡的小分割。如果你碰巧用Apple g ++編譯gtest。同時在gcc上安裝了gcc自制軟件,鏈接到gtest會導致這個錯誤。

所以用相同的編譯器編譯gtest和你的項目。 :D

相關問題