[英]gtest installed with conan: undefined reference to `testing::internal::GetBoolAssertionFailureMessage`
我使用cmake構建我的項目並使用conan將Google Test安裝為依賴項:
柯南文件.txt
[requires]
gtest/1.7.0@lasote/stable
[generators]
cmake
[imports]
bin, *.dll -> ./build/bin
lib, *.dylib* -> ./build/bin
CMakeLists.txt
PROJECT(MyTestingExample)
CMAKE_MINIMUM_REQUIRED(VERSION 2.8)
INCLUDE(conanbuildinfo.cmake)
CONAN_BASIC_SETUP()
ADD_EXECUTABLE(my_test test/my_test.cpp)
TARGET_LINK_LIBRARIES(my_test ${CONAN_LIBS})
測試/my_test.cpp
#include <gtest/gtest.h>
#include <string>
TEST(MyTest, foobar) {
std::string foo("foobar");
std::string bar("foobar");
ASSERT_STREQ(foo.c_str(), bar.c_str()); // working
EXPECT_FALSE(false); // error
}
建造
$ conan install --build=missing
$ mkdir build && cd build
$ cmake .. && cmake --build .
我可以使用ASSERT_STREQ
,但如果我使用EXPECT_FALSE
我會收到意外錯誤:
my_test.cpp:(.text+0x1e1): undefined reference to `testing::internal::GetBoolAssertionFailureMessage[abi:cxx11](testing::AssertionResult const&, char const*, char const*, char const*)'
collect2: error: ld returned 1 exit status
我的配置有什么問題?
問題是您正在使用默認設置(構建類型Release )安裝柯南依賴關系:
$ conan install --build=missing
# equivalent to
$ conan install -s build_type=Release ... --build=missing
默認設置可以在conan.conf
文件中看到
然后,您在默認構建類型為Debug的nix系統中使用cmake,這是一個單配置環境(與Visual Studio的多配置Debug / Release環境相對,與之相對),因此在執行以下操作時:
$ cmake .. && cmake --build .
# equivalent to
$ cmake .. -DCMAKE_BUILD_TYPE=Debug && cmake --build .
調試/發布版本的不兼容性導致該未解決的問題。 因此解決方案是使用與您已安裝的依賴項相匹配的相同構建類型:
$ cmake .. -DCMAKE_BUILD_TYPE=Release && cmake --build .
如果使用像Visual Studio這樣的多配置環境,則正確的方法是:
$ cmake .. && cmake --build . --config Release
在我這邊,我遇到這個問題是因為在 Redhat 7 上然后使用舊的 libstdc++。 對於柯南默認包二進制文件/庫來說太舊了。
我已經通過使用“--build gtest”arg 重建 gtest 來解決這個問題。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.