# Use 3rd party library with ROS Groovy & C++

Hi, I've been doing some research and though I found similar questions their solutions didn't work for me. I am having trouble with compiling my project while using a 3rd party library. I have the .h and the .o files for the library, but that developer is not currently able to give me the .cpp file.

I am a bit confused as to where exactly to put the .h and .o files and what to put in the CMakeLists file. libfile.h and libfile.o represent the 3rd party library files.

Currently I have both of these files in catkin_ws/src/mypackage/include/mypackage/ In my project code I have an include:

#include "mypackage/libfile.h"


In my CMakeLists.txt file I have:

#include_directories(include
${catkin_INCLUDE_DIRS} ) add_executable(mypackage src/mypackage_code.cpp) target_link_libraries(mypackage${libfile}
${catkin_LIBRARIES} )  When I do a catkin_make I get a lot of undefined reference to function errors in my project code referencing from this library that I believe are because catkin isn't linking to the other library, like: mypackage_code.cpp:(.text.startup+0x33a): undefined reference to 'some_function_in_3rdparty_library'  I've tried to only paste the information relevant to this issue to help others. If you want more specifics that's no problem. Thank you very much for your help. edit retag close merge delete ## Comments How do you set the value of libfile? Is it an absolute path? ( 2015-01-16 00:50:28 -0500 )edit I tried to make this question easier to understand, I guess that backfired. "libfile" here is just the name of my particular library, (RoboPiLib), with the header/object files RoboPiLib.h & RoboPiLib.o If that didn't answer your question, how should I define libfile? With link_directories(path)? ( 2015-01-16 08:39:19 -0500 )edit ## 1 Answer Sort by » oldest newest most voted Well, it is finding your headers, which is good, because it is getting to the linkedit step, where you get the undefined reference errors. First thing to check is to run with VERBOSE=1 before your command, e.g. VERBOSE=1 catkin_make. This will cause make to print out the exact commands it is running. Then you can look at the command which does the linking and look for your library in those arguments. At which point what you put in the ${libfile} CMake variable matters. You said you have .o files? That's pretty strange, usually the arguments to target_link_libraries is either a shared library (object), e.g. .so or a static object archive, e.g. .a. I'm not entirely sure how to integrate existing .o files directly into a new executable created by CMake. I found some links about it here:

http://www.cmake.org/pipermail/cmake/...

http://www.cmake.org/pipermail/cmake/...

http://stackoverflow.com/questions/14...

However, I would push back on the person giving you the .o file and ask for a static library instead (.a). Then you can just put the path to it in for libfile.

One more point is that once you have a library, shared or static, then you can instead put the name of the library, where the name is like /path/to/lib/lib<name>.so. This way it can be either a .so or a .a and can be located in multiple places and CMake will still find the right file. This is the difference in passing /path/to/libmy_library.a to the compiler and passing -lmy_library.

One more point is that you should be installing this library object if you want your install target to work.

If you want to release this package you are working on then you'll need to rethink this whole layout because distributing precomiled binaries is not a great solution for general reuse.

more

I have libftd2xx.a file in /usr/local/lib, I wrote in CmakeLists.txt

 target_link_libraries(imu \${catkin_LIBRARIES} ftd2xx)


I tried but it is showing error.

imu.cpp:(.text+0x5c3): undefined reference to FT_GetLibraryVersion'
imu.cpp:(.text+0x671): undefined reference to FT_Open
`
( 2015-01-20 06:27:45 -0500 )edit

@William Help me out and ans Here

( 2015-01-20 06:29:48 -0500 )edit