【发布时间】:2016-12-31 12:16:21
【问题描述】:
我使用cmake 构建我的项目并使用conan 安装Google Test 作为依赖项:
conanfile.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})
test/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内容也可能有用。 -
可能是
libcxx不匹配,从错误输出看来您应该使用libcxx=libstdc++11。如果在linux中(一般来说,不是多配置环境),你应该使用cmake .. -DCMAKE_BUILD_TYPE=Release,假设conan安装使用默认设置-s build_type=Release -
非常感谢,
-DCMAKE_BUILD_TYPE=Release解决了这个问题。 -
好!然后将其添加为答案
标签: c++ unit-testing googletest conan