ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | ros @ Robotics Stack Exchange
Ask Your Question
2

Linking dependencies on OSX

asked 2013-02-02 03:55:56 -0500

Hansg91 gravatar image

updated 2013-02-02 03:56:42 -0500

Hey,

I have been attempting to get ROS to work on OSX and am stuck when I try to link an executable with a dependency. I tried linking against yaml-cpp and tinyxml, both installed and linked according to homebrew, but I get the following message:

ld: library not found for -lyaml-cpp

Executing :

pkg-config --cflags --libs yaml-cpp

Gives me :

-I/usr/local/Cellar/yaml-cpp/0.5.0/include  -L/usr/local/Cellar/yaml-cpp/0.5.0/lib -lyaml-cpp

Doesn't that mean rosmake should be able to find it? For the record, I am linking in my CMakeLists.txt like this:

target_link_libraries(Controller yaml-cpp)

What am I doing wrong?

edit retag flag offensive close merge delete

2 Answers

Sort by ยป oldest newest most voted
2

answered 2013-02-02 08:01:31 -0500

WilliamWoodall gravatar image

You are adding yaml-cpp as a target, but the -L location of it is not on your path:

/usr/local/Cellar/yaml-cpp/0.5.0/lib

This means you need to use find_package or pkg-config in CMake to find this path at build time and add it your linker path using link_directories()

Also, you might want to use yaml-cpp version 0.3, because that is what ROS is using. See:

https://github.com/ros/homebrew-groovy/blob/master/yaml-cpp-0.3.rb

edit flag offensive delete link more

Comments

Thank you again. It seems I had both versions of yaml-cpp installed. I have some follow-up questions, would I need to do this on say Ubuntu as well? Did this change since groovy? I remember on fuerte that I could just link it like I showed. Can you give me an example of how I should link in?

Hansg91 gravatar image Hansg91  ( 2013-02-03 01:29:22 -0500 )edit

I tried making a small test package on Ubuntu and what I did does indeed work (add target_link_libraries and add rosdep to manifest). On the Ubuntu machine the lib was .so however and on my OSX it is a .a, does this make a difference? Why doesn't my ROS automatically use the path from pkg-config?

Hansg91 gravatar image Hansg91  ( 2013-02-04 06:10:22 -0500 )edit

My guess is that I have some environment setting that is messed up, causing the compiler to fail to see the libraries. What could it be?

Hansg91 gravatar image Hansg91  ( 2013-02-04 06:20:11 -0500 )edit

It depends on what you are doing, are you using rosbuild or catkin. Either way you need to find yaml-cpp in cmake before using it, it probably works on Ubuntu because it is installed in your library path, but you should not rely on this being the case on all systems, i.e. Homebrew and osx.

WilliamWoodall gravatar image WilliamWoodall  ( 2013-02-04 09:02:55 -0500 )edit

Check this out for a hint out how to do this with CMake: http://code.google.com/p/yaml-cpp/issues/detail?id=127

WilliamWoodall gravatar image WilliamWoodall  ( 2013-02-04 09:08:48 -0500 )edit

I see, that clears it up for me a lot. Too bad you can't rely on that :)

Hansg91 gravatar image Hansg91  ( 2013-02-04 09:36:19 -0500 )edit

Ok I believe I have that part down now, however I get a different error now:

Hansg91 gravatar image Hansg91  ( 2013-02-04 12:41:25 -0500 )edit

Edit your original question if it is related to this still, otherwise open a new issue.

WilliamWoodall gravatar image WilliamWoodall  ( 2013-02-04 12:42:26 -0500 )edit
0

answered 2014-08-21 12:00:12 -0500

Jean-Luc Nacif Coelho gravatar image

updated 2014-08-21 23:14:36 -0500

Whenever the compilation gives you a linker error, it will tell you which library it didn't find (like "-yaml-cpp").

grep for that specific library (such as "grep -r -yaml-cpp *"), look for a .txt file that contains that switch, and replace it ("-yaml-cpp") for whatever "pkg-config --libs [lib name]" gives you (like "pkg-config --libs yaml-cpp", which gives you "-L/usr/local/Cellar/yaml-cpp/0.5.0/lib -lyaml-cpp").

After you do that, build using the command given to you by the error message (the one to reproduce the error) since this command will build the package without remaking the makefile.

The reason for this is that for some reason the CMake files for ROS do not use the correct way to tell the linker where the libraries are ("-L[lib name]"), at least for a clean OSX as far as I know.

PS: there was one exception: -lOgreMain

pkg-config couldn't find the library "ogre", so I had to find it manually. The library was in

"(-L)/usr/local/Cellar/ogre/lib (-lOgreMain)"

PPS: there was one more exception: -llog4cxx

the package was in

"(-L)/usr/local/Cellar/log4cxx/0.10.0/lib/ (-llog4cxx)"

edit flag offensive delete link more

Question Tools

Stats

Asked: 2013-02-02 03:55:56 -0500

Seen: 1,195 times

Last updated: Aug 21 '14