How to install libgtest.so with catkin install?
I have some working end to end rostests built and installed like:
# builds the test executable against the first test file
add_rostest_gtest(test-end2end
bag_tests/MY_TEST.test
test/end2end_test.cpp
src/container_sub.cpp)
target_link_libraries(test-end2end ${catkin_LIBRARIES})
target_include_directories(test-end2end PRIVATE include)
If I build and run using default configuration catkin tools and rostest, it works as expected
catkin build end2end_testing --catkin-make-args tests
rostest end2end_testing MY_TEST.test --text
However, if I try and do the same in a workspace that has been configured with an install location:
catkin config --install
when I run the test, I get:
...test-end2end: error while loading shared libraries: libgtest.so: cannot open shared object file: No such file or directory
Searching the workspace I found that the unfound executable is in the build dir:
build/end2end_testing/gtest/googlemock/gtest/libgtest.so
So my question is: how can I have it included or at least accessed from, the install dir?
(I could just run my tests from devel, but I want the CI to test being built in install, including all the tests, so it doesn't have to build/install everything twice)
Asked by LukeAI on 2022-08-23 09:26:25 UTC
Answers
error while loading shared libraries: libgtest.so: cannot open shared object file: No such file or directory
This indicates OS is not seeing the .so file in question in the path it's told to search for libraries.
Searching the workspace I found that the unfound executable is in the build dir:
build/end2end_testing/gtest/googlemock/gtest/libgtest.so
Assuming you ran the search command under the top dir of the workspace, libgtest.so
being found under build
in the workspace tells us that it's you who built that .so file. Since your workspace is now configured for installation (by catkin config --install
), the runtime environment of your workspace also needs to be configured for installation, which you can do by source
-ing setup.bash
file in Catkin's world. By default, catkin
sets install directory directly under the top directory in the workspace. So without changing directory locations, it can be source ./install/setup.bash
.
Check if echo $LD_LIBRARY_PATH
includes the path under the workspace's install
directory.
UPDATE:
build/end2end_testing/gtest/googlemock/gtest/libgtest.so
libgtest.so
being in build
, not under install
means that the .so file is not set to be installed.
Check CMakeLists.txt
file that contains the configuration for the .so file in question, make sure it has an installation rule for that file.
Btw, sounds like you're building gtest
by yourself instead of using the installer that installs pre-built files, where I don't expect you to see the mentioned issue. Do you really need to build by yourself?
UPDATE-2:
the
.so
is not manually configured in theCMakeLists
, it's built/placed in build automatically byadd_rostest_gtest
I see.
The direct reason why you're getting the following error is OS (the order of trigger is likely: rostest
<- cmake
<- catkin test
) doesn't see the mentioned dynamic library in the paths given by LD_LIBRARY_PATH
. When catkin is configured either with install or no-install, I doubt it'll look into build
directory.
test-end2end: error while loading shared libraries: libgtest.so: cannot open shared object file: No such file or directory
I tried locally (on docker) for a pkg that also defines add_rostest_gtest
, and I confirm that libgtest.so
is generated under build
.
# find build/ -iname *.so
build/pkg_foo/gtest/googlemock/gtest/libgtest.so
This lead to me saying this:
- In ROS or not, I think unit test in general is meant to be executed in non-installation option. Rationale is that common practice is to not install unit test codes so that unit test won't be available in the install space IMO. #q241467 supports my theory I guess.
- Particularly, (without looking into its code)
gtest
(and/oradd_rostest_gtest
implementatino) is likely defined so that it doesn't get installed evencatkin/cmake
is configured for installation, therefore it's .so gets installed into non-install space. This is just speculation.
Asked by 130s on 2022-08-25 10:43:13 UTC
Comments
sourcing install/setup.bash
adds /home/ME/projects/spss/install/lib
to the front of $LD_LIBRARY_PATH
, doesn't include doesn't make any difference to observed behaviour.
Asked by LukeAI on 2022-08-25 11:26:15 UTC
@LukeAI Ok I found one thing I forgot to include in my answer. See my update.
Asked by 130s on 2022-08-25 11:43:54 UTC
the .so
is not manually configured in the CMakeLists, it's built/placed in build automatically by add_rostest_gtest
Asked by LukeAI on 2022-08-26 03:20:15 UTC
@LukeAI, Ok I can repro your issue, and posted my update.
Asked by 130s on 2022-08-26 16:25:17 UTC
Comments
solution might be this https://answers.ros.org/question/82761/problem-with-linking-gtests-in-catkin/?answer=82826#post-id-82826
need to investigate...
Asked by LukeAI on 2022-08-25 11:30:50 UTC