无法在容器内找到gtest [英] Fail to find gtest inside a container
问题描述
我正在容器内工作.我想尝试gtest,所以首先我通过在容器内部 进行安装:
I am working inside a container. I want to try gtest so first I installed it by doing this inside the container:
- 从github/google/googletest下载源文件
- 通过
cmake CMakeLists.txt
构建项目 - 致电
make
-
cd lib
和cp */usr/lib
-
cd googlemock/include
和cp -r gmock/usr/local/include
-
cd googletest/include
和cp -r gtest/usr/local/include
- Download the source file from github/google/googletest
- build the project by
cmake CMakeLists.txt
- call
make
cd lib
andcp * /usr/lib
cd googlemock/include
andcp -r gmock /usr/local/include
cd googletest/include
andcp -r gtest /usr/local/include
此后,我将CMakeLists.txt文件创建为
After this I created a CMakeLists.txt file as
cmake_minimum_required(VERSION 3.13)
set(CMAKE_CXX_STANDARD 11)
find_package(GTest REQUIRED)
message("GTest_INCLUDE_DIRS = ${GTest_INCLUDE_DIRS}")
add_executable(myExecutable main.cpp)
target_link_libraries(myExecutable ${GTEST_LIBRARIES} pthread)
有了这个,我可以毫无问题地使用gtest了.(main.cpp包含一些测试)
With this, I could use gtest without problem. (main.cpp contained some tests)
然后我想对我拥有的ROS项目执行相同的操作,因此在创建了依赖gtest的工作区和程序包后,我做了 catkin_make
并得到了
Then I want to do the same for a ROS project I have, so after creating a workspace and a package that depends on gtest I did catkin_make
and I get
- +++ processing catkin package: 'ros_gtest'
-- ==> add_subdirectory(ros_gtest)
-- Could NOT find GTest (missing: GTest_DIR)
-- Could not find the required component 'GTest'. The following CMake error indicates that you either need to install the package with the same name or change your environment so that it can be found.
CMake Error at /opt/ros/noetic/share/catkin/cmake/catkinConfig.cmake:83 (find_package):
Could not find a package configuration file provided by "GTest" with any of
the following names:
GTestConfig.cmake
gtest-config.cmake
Add the installation prefix of "GTest" to CMAKE_PREFIX_PATH or set
"GTest_DIR" to a directory containing one of the above files. If "GTest"
provides a separate development package or SDK, be sure it has been
installed.
Call Stack (most recent call first):
ros_gtest/CMakeLists.txt:10 (find_package)
-- Configuring incomplete, errors occurred!
See also "/root/ros_gtest_example/build/CMakeFiles/CMakeOutput.log".
See also "/root/ros_gtest_example/build/CMakeFiles/CMakeError.log".
make: *** [Makefile:320: cmake_check_build_system] Error 1
在这种情况下,CMakeLists.txt开头为
In this case the CMakeLists.txt start as
cmake_minimum_required(VERSION 3.0.2)
project(ros_gtest)
## Compile as C++11, supported in ROS Kinetic and newer
# add_compile_options(-std=c++11)
## Find catkin macros and libraries
## if COMPONENTS list like find_package(catkin REQUIRED COMPONENTS xyz)
## is used, also find other catkin packages
find_package(catkin REQUIRED COMPONENTS
GTest
roscpp
rospy
std_msgs
)
我想知道为什么在这种情况下它不起作用,但在另一种情况下它起作用吗?
I wonder why it does not work in this case but it works in the other?
推荐答案
缺少 make install
,并且您不会复制任何gtest配置文件...
missing make install
and you don't copy any gtest config file...
恕我直言,您应该使用 FetchContent()
或/并了解CMake find_package()的工作原理...
IMHO, You should use FetchContent()
or/and learn how CMake find_package() work...
include(CTest)
if(BUILD_TESTING)
include(FetchContent)
FetchContent_Declare(
googletest
GIT_REPOSITORY https://github.com/google/googletest.git
GIT_TAG master)
set(gtest_force_shared_crt ON CACHE BOOL "" FORCE)
FetchContent_MakeAvailable(googletest)
endif()
ref:mizux/cmake-cpp
ref: mizux/cmake-cpp
这篇关于无法在容器内找到gtest的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!