Не удалось скомпилировать программу с библиотекой GoogleTest, установленной Конаном - PullRequest
0 голосов
/ 21 апреля 2020

Я пытался использовать GTest, установленный через менеджер пакетов Conan, но получаю скрытую ошибку.

main. cpp:

#include <gtest/gtest.h>

TEST(tests, t_first)
{
    ASSERT_EQ(1,1);
}

int main(int argc, char **argv) {
  ::testing::InitGoogleTest(&argc, argv);
  return RUN_ALL_TESTS();
}

CMakeLists.txt:

cmake_minimum_required(VERSION 2.8) 
project(ranges-v3 LANGUAGES CXX)  

set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)

include(${CMAKE_BINARY_DIR}/conanbuildinfo.cmake)
conan_basic_setup()

add_executable(main main.cpp)
target_link_libraries(main ${CONAN_LIBS})

conanfile.txt

[requires]
range-v3/0.9.1
fmt/6.2.0
gtest/1.10.0

[generators]
cmake

build. sh

mkdir build
cd build
conan install ..
cmake ..
make
cp -f bin/main ../main

Я строю проект, используя usung build.sh, и получаю следующее сообщение:

Configuration:
[settings]
arch=x86_64
arch_build=x86_64
build_type=Release
compiler=gcc
compiler.libcxx=libstdc++
compiler.version=7
os=Linux
os_build=Linux
[options]
[build_requires]
[env]

conanfile.txt: Installing package
Requirements
    fmt/6.2.0 from 'conan-center' - Cache
    gtest/1.10.0 from 'conan-center' - Cache
    range-v3/0.9.1 from 'conan-center' - Cache
Packages
    fmt/6.2.0:d351525cc53ebe68279edf1978846402420066e7 - Cache
    gtest/1.10.0:4a8c5b4cd3b4d45b83fff85d53160ea02ae5fa2d - Cache
    range-v3/0.9.1:5ab84d6acfe1f23c4fae0ab88f26e3a396351ac9 - Cache

Installing (downloading, building) binaries...
fmt/6.2.0: Already installed!
gtest/1.10.0: Already installed!
range-v3/0.9.1: Already installed!
conanfile.txt: Generator cmake created conanbuildinfo.cmake
conanfile.txt: Generator txt created conanbuildinfo.txt
conanfile.txt: Generated conaninfo.txt
conanfile.txt: Generated graphinfo
-- Conan: Adjusting output directories
-- Conan: Using cmake global configuration
-- Conan: Adjusting default RPATHs Conan policies
-- Conan: Adjusting language standard
-- Current conanbuildinfo.cmake directory: /home/bogdasar/Documents/C++_Programming/HuffmanCode/build
-- Conan: Compiler GCC>=5, checking major version 7
-- Conan: Checking correct version: 7
-- Configuring done
-- Generating done
-- Build files have been written to: /home/bogdasar/Documents/C++_Programming/HuffmanCode/build
[ 50%] Building CXX object CMakeFiles/main.dir/main.cpp.o
[100%] Linking CXX executable bin/main
CMakeFiles/main.dir/main.cpp.o: In function `testing::AssertionResult testing::internal::CmpHelperEQFailure<int, int>(char const*, char const*, int const&, int const&)':
main.cpp:(.text._ZN7testing8internal18CmpHelperEQFailureIiiEENS_15AssertionResultEPKcS4_RKT_RKT0_[_ZN7testing8internal18CmpHelperEQFailureIiiEENS_15AssertionResultEPKcS4_RKT_RKT0_]+0x87): undefined reference to `testing::internal::EqFailure(char const*, char const*, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, bool)'
collect2: error: ld returned 1 exit status
CMakeFiles/main.dir/build.make:94: recipe for target 'bin/main' failed
make[2]: *** [bin/main] Error 1
CMakeFiles/Makefile2:67: recipe for target 'CMakeFiles/main.dir/all' failed
make[1]: *** [CMakeFiles/main.dir/all] Error 2
Makefile:83: recipe for target 'all' failed
make: *** [all] Error 2

Но если я удалю TEST из main.cpp, скомпилирую программу без теста, после запуска программы получим следующий вывод:

[==========] Running 0 tests from 0 test suites.
[==========] 0 tests from 0 test suites ran. (0 ms total)
[  PASSED  ] 0 tests.

1 Ответ

0 голосов
/ 22 апреля 2020

Я решил проблему:

Мне помог обертка CMake для Конана.

Смотрите здесь: https://github.com/conan-io/cmake-conan

...