2016-05-19 35 views
1

我下載googletest並將其構建在名爲build的子目錄中。
於是,我寫了一個名爲main.cpp文件下面的代碼:GoogleTest:CLang錯誤編譯ASSERT_FALSE(false)

#include <gtest/gtest.h> 
TEST(FOO, BAR) { ASSERT_FALSE(false); } 

很簡單的。
它依賴於main函數已提供googletest如果您鏈接libgtestmain.a庫的事實。

GCC(V5.3.1)編譯使用它的以下命令:

g++ -L./googletest/build/googlemock/gtest -L./googletest/build/googlemock -I./googletest/googletest/include/ -lgmock -lgtest -lgtest_main -lgmock_main -pthread -std=c++11 main.cpp 

反正鐺(v3.6.2)使用相同的命令不編譯:

clang++ -L./googletest/build/googlemock/gtest -L./googletest/build/googlemock -I./googletest/googletest/include/ -lgmock -lgtest -lgtest_main -lgmock_main -pthread -std=c++11 main.cpp 

的錯誤是以下之一:

/tmp/main-4127ae.o: In function 'FOO_BAR_Test::TestBody()':
main.cpp:(.text+0x7b): undefined reference to `testing::internal::GetBoolAssertionFailureMessage(testing::AssertionResult const&, char const*, char const*, char const*)'
clang: error: linker command failed with exit code 1 (use -v to see invocation)

該代碼包含幾乎唯一的ASSERT_FALSE(false)聲明(這是一個分鐘imal,完整的例子,但它仍然沒有編譯),所以我會說這個問題不在代碼本身。
同樣的問題也出現在下面的語句:

TEST(FOO, BAR) { ASSERT_TRUE(true); } 

是,由於一個問題googletest,以或什麼?
我試圖弄清楚,但我有點麻煩,看代碼googletest

注意

我已經無法找到既不公開,也不是googletest一個封閉的問題,所以我也打開了它一票上github上
有一段時間我可能會發布鏈接到問題。

+1

也許這就是ABI不兼容性,因爲你使用gcc構建了gtest,並且將它鏈接到了用clang編譯的東西? – galsh83

+0

可能與編譯錯誤無關,但您應該針對'libgtest_main.a'或'libgmock_main.a'鏈接,而不是兩者。 –

回答