我用cmake建立我的項目,conan安裝Google Test的依賴性:GTEST安裝了柯南:未定義的引用`測試::內部:: GetBoolAssertionFailureMessage`
conanfile.txt
[requires]
gtest/[email protected]/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
什麼問題與我的配置?
在其操作系統和編譯器(帶版本)你在運行嗎? ''conaninfo.txt''和''CONAN_LIBS''內容可能也很有用。 – drodri
它可能是一個''libcxx''不匹配,從錯誤輸出看來你應該使用''libcxx = libstdC++ 11''。如果在linux中(通常不是多配置的envs),你應該使用''cmake .. -DCMAKE_BUILD_TYPE = Release'',假設conan安裝使用默認設置''-s build_type = Release'' – drodri
謝謝非常多,'-DCMAKE_BUILD_TYPE = Release'修復了這個問題。 – maiermic