Ask Your Question
0

Linking external libraries CGAL and GMP

asked 2012-10-19 05:47:46 -0600

henge266 gravatar image

updated 2014-01-28 17:13:59 -0600

ngrennan gravatar image

Hi,

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.
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 ... (more)

edit retag flag offensive close merge delete

Comments

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

Mani gravatar imageMani ( 2012-10-19 09:20:48 -0600 )edit

2 Answers

Sort by ยป oldest newest most voted
1

answered 2012-10-19 20:42:06 -0600

Mani gravatar image

updated 2013-05-01 18:01:21 -0600

130s gravatar image

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

Link

http://stackoverflow.com/a/6980807/1215297

edit flag offensive delete link more

Comments

You may have to use pkg-config as well. There's a FindPkgConfig module.

tfoote gravatar imagetfoote ( 2013-01-14 15:57:14 -0600 )edit
0

answered 2019-05-13 13:43:09 -0600

ssohin gravatar image

updated 2019-05-13 13:45:07 -0600

The error seems to be from CGAL not linking libGmp as it depends on it. Using target_link_libraries(example CGAL::CGAL) instead of using the CMake variable target_link_libraries(example ${CGAL_LIBRARIES}) solves the issue.

https://stackoverflow.com/a/56031744/...

edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

Stats

Asked: 2012-10-19 05:47:46 -0600

Seen: 4,755 times

Last updated: May 13