Rosanswers logo


I want to use two external libraries:

In my qt project, I added

LIBS += -lCGAL -lgmp

to my .pro file and it works well.

When I try to use it in my ros project, I tried

find_library(CGAL_LIBRARY CGAL /usr/local)
find_library(GMP_LIBRARY gmp /usr/lib)

target_link_libraries(ros_project ${CGAL_LIBRARY} ${GMP_LIBRARY} )

Its seems that the CGAL library is linked correctly, but the GMP library is not. I get the following error for example:

error: undefined reference to `__gmpq_init'

Taking a look at the "CMakeCache.txt" in the ros project folder shows:

# EXTERNAL cache entries

//Path to a library.

//Path to a library.

The command sudo dpkg -L libgmp-dev shows:


so I guess the path is found correctly and I have absolutely no idea why I get the undefined reference. I'am using Ubuntu 12.04 64bit. Does anyone have an idea how to solve this?

Thanks in advance



grep --color -Ri "gmp" ./build:


./build/CMakeFiles/basic_shapes.dir/build.make:../bin/basic_shapes: /usr/lib/x86_64-linux-gnu/libgmp.so

./build/CMakeFiles/basic_shapes.dir/link.txt:/usr/bin/c++ -O2 -g -pthread CMakeFiles/basic_shapes.dir/src/basic_shapes.o CMakeFiles/basic_shapes.dir/media/truecrypt1/coding/Cpp/MastersThesis/logplan2013_code/trackGenerator/trackGenerator/src/trackGenerator.o -o ../bin/basic_shapes -rdynamic -L/opt/ros/fuerte/lib -L/usr/local/boost_1_51_0/stage/lib -L/usr/local/lib -L/media/truecrypt1/coding/Cpp/MastersThesis/logplan2013_code/trackGenerator/build_lib -L/media/truecrypt1/coding/Cpp/MastersThesis/logplan2013_code/getVoronoi/build_lib -lroscpp -lrostime -lrosconsole -lroscpp_serialization -lxmlrpcpp /usr/local/boost_1_51_0/stage/lib/libboost_system.a /usr/local/boost_1_51_0/stage/lib/libboost_thread.a /usr/local/lib/libCGAL.so -lgmp /media/truecrypt1/coding/Cpp/MastersThesis/logplan2013_code/trackGenerator/build_lib/libtrackGenerator.a /media/truecrypt1/coding/Cpp/MastersThesis/logplan2013_code/getVoronoi/build_lib/libgetVoronoi.a -Wl,-rpath,/opt/ros/fuerte/lib:/usr/local/lib

Binary file ./build/CMakeFiles/basic_shapes.dir/media/truecrypt1/coding/Cpp/MastersThesis/logplan2013_code/trackGenerator/trackGenerator/src/trackGenerator.o matches

Binary file ./build/CMakeFiles/basic_shapes.dir/media/truecrypt1/coding/Cpp/MastersThesis/logplan2013_code/voronoi/src/AlphaShape.o matches

Binary file ./build/CMakeFiles/basic_shapes.dir/media/truecrypt1/coding/Cpp/MastersThesis/logplan2013_code/voronoi/src/DPLineSimplification.o matches

Binary file ./build/CMakeFiles/basic_shapes.dir/media/truecrypt1/coding/Cpp/MastersThesis/logplan2013_code/voronoi/src/PolygonEnvironment.o matches

Binary file ./build/CMakeFiles/basic_shapes.dir/media/truecrypt1/coding/Cpp/MastersThesis/logplan2013_code/voronoi/src/VoronoiDiagram.o matches

Binary file ./build/CMakeFiles/basic_shapes.dir/src/basic_shapes.o matches

Occurrence of gmp is marked bold. Before the third and last occurrence of gmp, the path to the working library libCGAL.so is given, but for gmp only -lgmp, is this part of the problem?

Mani you said: "Please check all occurrences in Makefiles to make sure the build system is doing its job correctly". Where has gmp to occur when the build System has done the job correctly?


Using find_package(GMP REQUIRED) in CMakeLists.txt results in following:

CMake Warning at CMakeLists.txt:55 (find_package):
  Could not find module FindGMP.cmake or a configuration file for package

  Adjust CMAKE_MODULE_PATH to find FindGMP.cmake or set GMP_DIR to the
  directory containing a CMake configuration file for GMP.  The file will
  have one of the following names:


[rosbuild] Including /opt/ros/fuerte/share/roscpp/rosbuild/roscpp.cmake
[rosbuild] Including /opt/ros/fuerte/share/rospy/rosbuild/rospy.cmake
[rosbuild] Including /opt/ros/fuerte/share/roslisp/rosbuild/roslisp.cmake
[rosbuild] Building package sendPgmMarker
-- Configuring done
-- Generating done

I couldn't find a file named GMPConfig.cmake or gmp-config.cmake. I used the ubuntu repositories to install gmp.

Originally posted by henge266 on ROS Answers with karma: 1 on 2012-10-19

Post score: 0

Original comments

Comment by Mani on 2012-10-19:
One more step to debug is to run grep --color -Ri "gmp" ./build in your package folder. Please check all occurrences in Makefiles to make sure the build system is doing its job correctly


1 Answer 1


Rosanswers logo

I guess you need to use find_package instead of find_library in your CMakeList.txt:



Originally posted by Mani with karma: 1704 on 2012-10-19

This answer was ACCEPTED on the original site

Post score: 1

Original comments

Comment by tfoote on 2013-01-14:
You may have to use pkg-config as well. There's a FindPkgConfig module.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.