用GoogleTest库编译程序失败,由柯南安装。

我试着使用通过Conan包管理器安装的GTest,但得到一个underwritten错误。

main.cpp.txt: CMakeLists:

#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

构建.sh

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

我正在建立项目,通过使用 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

但如果我删除 TESTmain.cpp在没有测试的情况下编译程序,运行程序后,得到如下输出。

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

解决方案:

我解决了这个问题。

Conan的CMake包装器帮我解决了问题.

请看这里。https:/github.comconan-iocmak-conan。

给TA打赏
共{{data.count}}人
人已打赏
解决方案

如何在Java 8中CombineMerge两个Map of Map of Lists(Map<String, Map<Enum, List<String>>>)。

2022-4-22 10:08:57

解决方案

如何保存一个HTML FORM数据,以便将来使用。

2022-4-22 10:08:59

0 条回复 A文章作者 M管理员
    暂无讨论,说说你的看法吧
个人中心
购物车
优惠劵
今日签到
有新私信 私信列表
搜索