1

My c++ program was having runtime errors (crash on mutex lock). Exceptions that were not coming directly from my code but from some libraries it used. I started to track down the problem and found out that I had a library (giskard_core, but that doesn't matter) listed in CMakeLists.txt in find_package(catkin REQUIRED COMPONENTS ... giskard_core) which I was not using at the moment. Commenting it out fixed the crash I was investigating. Pulling it back to the find_package list brought the crash back. My code was really simple, literally just a main function and bare bones of a ROS application, and surely was not using the library that was causing the problems.

What is going on? Can a package bring an error by just being listed in find_package in CMakeLists.txt?

Lubiluk
  • 704
  • 5
  • 12

1 Answers1

0

I suspect that your code probably has an error in how it implements catkin stuff. Since it's actually compiling without that project, I also suspect that it has some pre-processor guards which are only enabled when catkin has been found.

Does something like this exist in your CMakeLists.txt?

if (Catkin_FOUND)
  add_definitions(-DCATKIN_FOUND)
endif (Catkin_FOUND)

Also does something like this exist in your code?

#ifdef CATKIN_FOUND
  mutex.lock()
#endif

If so, that could explain the issues that you're seeing. You'd need to fix the use of whatever Catkin functionality your project implements.

Stewart
  • 4,356
  • 2
  • 27
  • 59
  • 1
    Well, my code does not implement anything yet. It's the simplest ROS program with just `main` function. But just pulling in the guilty library into find_package makes it crash. `CMakeLists.txt` has no conditionals nor has the C++ code. You mentioned pre-processor guards... but should the compiler ever see the code from the library when it's not even used? – Lubiluk Jul 30 '17 at 15:33
  • In this case, I suspect that `catkin` initializes some global object and that initialization causes the crash, likely due to some missing initial configuration. Check out [this link](http://wiki.ros.org/catkin/CMakeLists.txt) and check that your CMakeLists.txt configures catkin according to those instructions. – Stewart Aug 06 '17 at 18:43