Я сейчас изучаю Конана. В качестве практического проекта я хотел бы создать библиотеку с модульными тестами (я хорошо знаю, что использование conan для gtest - не самая полезная вещь, но это только пример).
Каталог моего проекта:
- build
- src
- тесты
- conanfile. txt
- CMakeLists.txt
My conanfile.txt
[requires]
gtest/1.10.0
[generators]
cmake
My CMakeLists.txt:
cmake_minimum_required(VERSION 3.5)
project(ralib)
enable_testing()
include(${CMAKE_BINARY_DIR}/conanbuildinfo.cmake)
conan_basic_setup()
add_library(ralib INTERFACE)
add_executable(array_tests tests/array_tests.cpp)
target_link_libraries(array_tests ${CONAN_LIBS})
add_test(NAME array_tests WORKING_DIRECTORY ${CMAKE_BINARY_DIR}/bin COMMAND array_tests)
My array_tests. cpp:
#include <gtest/gtest.h>
#include <iostream>
TEST(Array, test){
std::cout << "g" << std::endl;
EXPECT_EQ(1, 1);
}
С build
:
./bin/array_tests
Ошибка при выполнении array_tests
munmap_chunk(): invalid pointer
Aborted (core dumped)
С build
:
conan install .. && cmake .. && cmake --build . -- -j8 && ctest
Вывод:
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
gtest/1.10.0 from 'conan-center' - Cache
Packages
gtest/1.10.0:4a8c5b4cd3b4d45b83fff85d53160ea02ae5fa2d - Cache
Installing (downloading, building) binaries...
gtest/1.10.0: 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/domane/dev/dlr/ravis/ralib/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/domane/dev/dlr/ravis/ralib/build
Scanning dependencies of target array_tests
[ 50%] Building CXX object CMakeFiles/array_tests.dir/tests/array_tests.cpp.o
[100%] Linking CXX executable bin/array_tests
[100%] Built target array_tests
Test project /home/domane/dev/dlr/ravis/ralib/build
Start 1: array_tests
1/1 Test #1: array_tests ......................***Exception: Child aborted 0.02 sec
0% tests passed, 1 tests failed out of 1
Total Test time (real) = 0.02 sec
The following tests FAILED:
1 - array_tests (Child aborted)
Errors while running CTest
Любые подсказки, почему это не работает?
Я добавил gtest_main через target_link_libraries не помогло.