Linking external libraries CGAL and GMP
Hi,
I want to use two external libraries:
- CGAL (Computational Geometry Algorithms Library, http://www.cgal.org/)
- GMP (GNU Multiple Precision Arithmetic Library, http://gmplib.org/)
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.
CGAL_LIBRARY:FILEPATH=/usr/local/lib/libCGAL.so
//Path to a library.
GMP_LIBRARY:FILEPATH=/usr/lib/x86_64-linux-gnu/libgmp.so
The command sudo dpkg -L libgmp-dev
shows:
/.
/usr
/usr/lib
/usr/lib/x86_64-linux-gnu
/usr/lib/x86_64-linux-gnu/libgmp.a
/usr/lib/x86_64-linux-gnu/libgmpxx.a
/usr/include
/usr/include/gmp.h
/usr/include/gmpxx.h
/usr/include/gmp-x86_64.h
/usr/share
/usr/share/doc
/usr/share/doc/libgmp-dev
/usr/share/doc/libgmp-dev/NEWS.gz
/usr/share/doc/libgmp-dev/AUTHORS
/usr/share/doc/libgmp-dev/README
/usr/share/doc/libgmp-dev/copyright
/usr/lib/x86_64-linux-gnu/libgmp.so
/usr/lib/x86_64-linux-gnu/libgmpxx.so
/usr/share/doc/libgmp-dev/changelog.Debian.gz
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
Hendrik
Edit:
grep --color -Ri "gmp" ./build:
./build/CMakeCache.txt:GMP_LIBRARY:FILEPATH=/usr/lib/x86_64-linux-gnu/libgmp.so
./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 ...
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