Ask Your Question
0

How to link C library in Cmake file?

asked 2015-01-19 04:55:14 -0600

KDROS gravatar image

updated 2015-01-20 09:36:16 -0600

Tom Moore gravatar image

I was using one ftdi library to communicate with robot, to run that piece of code i used to compile like

gcc -o demo demo.c -L. -lftd2xx -Wl,-rpath,/usr/local/lib

Now i am using this C library in ROS, then how to link that library with ROS, What should I change in CmakeLists.txt and how to write that.

edit retag flag offensive close merge delete

3 Answers

Sort by ยป oldest newest most voted
2

answered 2015-01-19 05:55:14 -0600

BennyRe gravatar image

Add the path to the library to target_link_libraries

edit flag offensive delete link more

Comments

Ok. Means like this target_link_libraries(odom ${catkin_LIBRARIES} /usr/local/lib), Should I change include directory also? Same problem is it possible to do in launch file? What is env value? Is it same as target_link_libraries?

KDROS gravatar imageKDROS ( 2015-01-19 06:24:59 -0600 )edit

/usr/local/lib should be automatically added by cmake. You only have to add your special libraries, in your case ltd2xx I guess. A launch file has nothing to do with linking. The env value is documented here.

BennyRe gravatar imageBennyRe ( 2015-01-19 06:48:27 -0600 )edit

my library is ftd2xx and (-l) is option for library name. According to you it will search and path of that library automatically. is it?

KDROS gravatar imageKDROS ( 2015-01-19 10:37:36 -0600 )edit
1

target_link_libraries(odom ${catkin_LIBRARIES} ftd2xx) should work.

DevonW gravatar imageDevonW ( 2015-01-19 15:42:16 -0600 )edit
1

Yes it searches automatically.

BennyRe gravatar imageBennyRe ( 2015-01-20 00:54:57 -0600 )edit

I tried that one but it is showing error.

imu.cpp:(.text+0x5c3): undefined reference to 'FT_GetLibraryVersion'

imu.cpp:(.text+0x671): undefined reference to 'FT_Open'

imu.cpp:(.text+0x6d4): undefined reference to 'FT_SetBaudRate' How to write -rpath in CMakeLists.txt

KDROS gravatar imageKDROS ( 2015-01-20 05:32:06 -0600 )edit

You don't need -rpath Where did you put libftd2xx.so? Did you write target_link_libraries(odom <path to libftd2xx.so> ${catkin_LIBRARIES})

BennyRe gravatar imageBennyRe ( 2015-01-20 05:51:45 -0600 )edit

@BennyRe I tried

target_link_libraries(odom /usr/local/lib/libftd2xx.a ${catkin_LIBRARIES})
target_link_libraries(odom ${catkin_LIBRARIES} ftd2xx)

and another combination too, still it is showing error

KDROS gravatar imageKDROS ( 2015-01-20 06:33:32 -0600 )edit
0

answered 2015-01-22 01:36:21 -0600

Wolf gravatar image

Add the path to your lib using link directories

link_directories( /path/to/your/lib )

and then use

target_link_libraries(odom ${catkin_LIBRARIES} ftd2xx)
edit flag offensive delete link more

Comments

Not working. Plz check my new que

KDROS gravatar imageKDROS ( 2015-01-22 04:01:56 -0600 )edit
0

answered 2015-01-22 01:08:21 -0600

KDROS gravatar image

I copied my libftd2xx.* files to /opt/ros/hydro/lib/ then I tried with

target_link_libraries(odom ${catkin_LIBRARIES} ftd2xx)

Still same error is coming. what wrong I am doing.

edit flag offensive delete link more

Comments

Please do not post comments as an answer. In which ubuntu package is libftd2xx included? What do you mean with libftd2xx.*? What kind of files are these? Manually copying libs to /opt/ros/hydro/lib/ is not a good idea.

BennyRe gravatar imageBennyRe ( 2015-01-22 01:21:55 -0600 )edit

I am using 12.04 and libftd2xx.* means .a and .so files.

KDROS gravatar imageKDROS ( 2015-01-22 02:03:44 -0600 )edit

With which debian package did you install libftd2xx?

BennyRe gravatar imageBennyRe ( 2015-01-22 02:12:45 -0600 )edit

I installed from here,In C its working fine.But I hv to use it by ROS node check my code here. plz tell me what wrong I am doing. Code is correct

KDROS gravatar imageKDROS ( 2015-01-22 04:10:57 -0600 )edit

Did you exactly follow the instructions from the readme? Especially the chmod and ln step?

BennyRe gravatar imageBennyRe ( 2015-01-22 05:20:44 -0600 )edit

yes, that is why In C it is working properly.

KDROS gravatar imageKDROS ( 2015-01-22 06:20:04 -0600 )edit

Your Answer

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

Add Answer

Question Tools

1 follower

Stats

Asked: 2015-01-19 04:55:14 -0600

Seen: 2,993 times

Last updated: Jan 22 '15