2

Since yesterday none of my packages containing tests build. Catkin complains it cannot find gtest when using catkin_add_gtests(), since GTEST_FOUND is FALSE. You can see this in the error msg below, with the custom output I added to my CMakeLists. Up to yesterday, GTEST_FOUND was TRUE when catkin_add_gtests() was called.

This is the error I always get. In this case I'm trying to build a mockup package on a clean catkin workspace:

Errors     << silly_pkg:cmake /home/paco/catkin_ws2/logs/silly_pkg/build.cmake.002.log                                                                                                                                                                                                                                
Not searching for unused variables given on the command line.
Re-run cmake no build system arguments
-- Using CATKIN_DEVEL_PREFIX: /home/paco/catkin_ws2/devel/.private/silly_pkg
-- Using CMAKE_PREFIX_PATH: /home/paco/catkin_ws2/devel;/opt/ros/kinetic
-- This workspace overlays: /home/paco/catkin_ws2/devel;/opt/ros/kinetic
-- Using PYTHON_EXECUTABLE: /usr/bin/python
-- Using Debian Python package layout
-- Using empy: /usr/bin/empy
-- Using CATKIN_ENABLE_TESTING: ON
-- Call enable_testing()
-- Using CATKIN_TEST_RESULTS_DIR: /home/paco/catkin_ws2/build/silly_pkg/test_results
-- Using Python nosetests: /usr/bin/nosetests-2.7
-- catkin 0.7.11
-- GTEST_FOUND: FALSE
CMake Warning at /opt/ros/kinetic/share/catkin/cmake/test/gtest.cmake:149 (message):
  skipping gtest 'test_silly_pkg' in project 'silly_pkg' because gtest was
  not found
Call Stack (most recent call first):
  /opt/ros/kinetic/share/catkin/cmake/test/gtest.cmake:79 (_catkin_add_executable_with_google_test)
  /opt/ros/kinetic/share/catkin/cmake/test/gtest.cmake:28 (_catkin_add_google_test)
  CMakeLists.txt:28 (catkin_add_gtest)


CMake Error at /home/paco/catkin_ws2/src/silly_pkg/CMakeLists.txt:33 (target_link_libraries):
  Cannot specify link libraries for target "test_silly_pkg" which is not
  built by this project.


-- Configuring incomplete, errors occurred!
See also "/home/paco/catkin_ws2/build/silly_pkg/CMakeFiles/CMakeOutput.log".
See also "/home/paco/catkin_ws2/build/silly_pkg/CMakeFiles/CMakeError.log".
cd /home/paco/catkin_ws2/build/silly_pkg; catkin build --get-env silly_pkg | catkin env -si  /usr/bin/cmake /home/paco/catkin_ws2/src/silly_pkg --no-warn-unused-cli -DCATKIN_DEVEL_PREFIX=/home/paco/catkin_ws2/devel/.private/silly_pkg -DCMAKE_INSTALL_PREFIX=/home/paco/catkin_ws2/install; cd -

I am using catkin 0.7.11, libgtest-dev 1.7.0 and cmake 3.5.1. I use ROS Kinetic with Ubuntu 16.04. The only thing I did yesterday was reinstalling ROS Kinetic, but the package versions are exactly the same. Did anybody have this problem? Do you have any ideas on what could be happening?

EDIT 3/09/18:

By comparing with a functional catkin+gtest workspace in a different computer, I found out that the main difference is in the results of /opt/ros/kinetic/share/catkin/cmake/test/gtest.cmake. In the functional workspace, line 292 evaluates to TRUE (gtest/gmock is not a target) while in my workspace it evaluates to FALSE. This is because in my workspace running find_package(GMock QUIET) (line 287) sets gmock and gtest as imported targets, which does not happen in the other computer. Why is this different?

Thanks TikO for your help!

PacoGG
  • 21
  • 3
  • 1
    If you have found a solution, please add an answer to your own question below. Questions are not supposed to have an answer embedded in them, nor should they have a "(SOLVED)" written on them. You can instead use the check mark button to annotate an answer which was the most useful to you. – E_net4 Sep 17 '18 at 15:22

2 Answers2

0

Since you wrote that cmake does not find the libraries and that you have reinstalled Kinetic, I assume that you have a freshly installed machine or wiped out gtest libraries by accident. If you install libgtest-dev, you only get the sources which you need to build and install like this:

sudo apt-get install libgtest-dev
mkdir /tmp/gtest_build && cd /tmp/gtest_build
cmake /usr/src/gtest
make
#copy or symlink libgtest.a and ligtest_main.a to /usr/lib folder
sudo cp *.a /usr/lib

After this routine, you should be able to build again without cmake complaining.

Optional

If you have limited rights on your machine and you are not allowed to install the libraries in that way, just copy them into some home folder like

mkdir ~/lib && cp *.a ~/lib

But be aware of the fact, that you have to call catkin in the following way:

LIBRARY_PATH=~/lib GTEST_ROOT=~/lib catkin_make

LIBRARY_PATH tells the linker where to find the libraries, while GTEST_ROOT gives cmake the location hints for it's checks.

Reference: https://github.com/tik0/gtest_ros_example

Tik0
  • 2,499
  • 4
  • 35
  • 50
  • Thanks! I think this would be the solution if I needed to link against the libraries. But, as far as I know, catkin_add_gtests() finds the files in /usr/src and /usr/include to compile gtest with your catkin packages. This is done in order to compile your tests with the same options as your code, according to the libgtest README. – PacoGG Aug 26 '18 at 16:07
  • I tried it and, as expected, cmake complains that it cannot build gtest as an imported library because "because another target with the same name already exists". – PacoGG Aug 26 '18 at 16:09
  • Ok, got you. Could you just upload your `CMakeLists.txt` or the project? The point is, that `find_package(GTest REQUIRED)` is will return FALSE when it does not find the pre-built libraries in your system folders. Thus it does not correlate with your error. Could it be, that some sub-project tries to find gtest via `find_package`? – Tik0 Aug 26 '18 at 20:16
  • Exactly, I am afraid that find_package is the origin of the problem. See the latest question update. – PacoGG Sep 03 '18 at 11:39
  • I assume that both systems use different find-package modules for either gmock or gtest (system-wide vs ROS-internals). Run cmake in debug mode (e.g. `-Wdev`, `--debug-output` and `--trace`) and compare both outputs. It could also help to investigate both environments via `env`. – Tik0 Sep 03 '18 at 12:15
0

SOLUTION FOUND

gmock and gtest were being set to imported target because the suggested manual compilation of libgtest had created a FindGMock.cmake file inside /usr/share/cmake-3.5/Modules. This file was being called by the find(GMock QUIET) in catkin_add_gtests(), therefore setting the imported target. Just deleting FindGMock.cmake solved the issue.

PacoGG
  • 21
  • 3