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

How to properly install packages from source?

asked 2018-06-27 04:27:31 -0600

Hypomania gravatar image

Hi,

I have been reading on how to install packages INTO ROS that aren't included in the ROS installation for a while now and I still don't get it. I am trying to modify source before installing, hence I would like to build it myself.

I am using Kinetic (Ubuntu 16.04 LTS) distro using catkin filesystem. The package I am trying to install is this: serial

It is available as a .deb package so initially I installed it using sudo apt-get install ros-kinematic-serial and that installed fine.

  1. First of all, I don't quite get how a package like this one works when installed (or any ROS package). I checked its CMakeLists.txt file, it only installs headers and an example binary file. Going into cd /opt/ros/kinetic/share/serial there is only package.xml file and a cmake folder with serialConfig.cmake and serialConfig-version.cmake files. I compiled a basic ROS node using this library and it works fine, so how does ROS know where to find the src files if it only has headers and cmake configs installed?

  2. Secondly, if I try to install package from source into ROS, what's the proper way of doing it? I have tried:

    cd ~/catkin_ws/src

    git clone https://github.com/wjwwood/serial.git

    cd ~/catkin_ws/ && catkin_make

    source ~/catkin_ws/devel/setup.bash

    That works fine, my example node works and I can adjust the source to my liking, but the package is installed to my catkin workspace and not the global ROS path. How do I add the package into the ROS environment so that something like rospack listcan identify it?

  3. Lastly, how come after catkin_make I can't find my package using rosrun my_package serial_example_node?

Any help is really appreciated!

edit retag flag offensive close merge delete

Comments

Something for the future: please don't ask multiple questions in a single post. The question title asks how to properly install pkgs from source, but the question text then goes on and adds two to three conceptual questions. Those additional questions are essentially 'invisible' this way.

gvdhoorn gravatar image gvdhoorn  ( 2018-06-27 05:15:02 -0600 )edit

1 Answer

Sort by ยป oldest newest most voted
8

answered 2018-06-27 05:09:57 -0600

gvdhoorn gravatar image

updated 2018-06-27 05:12:14 -0600

I try to install package from source into ROS, what's the proper way of doing it?

See #q252478 for an example workflow that I consider to be "the proper way". The steps you list in your question are almost correct, but if you don't take care of installing all dependencies, CMake will start complaining when it evaluates the CMakeLists.txt of whatever package(s) you're trying to build and they need a dependency that isn't present.

That works fine, my example node works and I can adjust the source to my liking, but the package is installed to my catkin workspace and not the global ROS path. How do I add the package into the ROS environment so that something like rospack list can identify it?

The way ROS Catkin workspaces work is that they overlay each other (more docs). Like an onion, each workspace layers on top of the previous one. The ROS installation in /opt/ros is essentially an install space, and your own personal workspace (ie: the first one you typically create) will overlay that one, and have its own source, build and devel space. In some cases, you'll want your workspace to have an install space as well, but that is not required for regular development work.

The process of overlaying makes all the packages in the underlying workspace available to the one that builds on top of it.

So in a situation with two workspaces -- say $HOME/ws_a and $HOME/ws_b -- in which the second overlays (or extends) the first, every pkg in ws_a can be rosrunned, roslaunched and found by rospack find after you've activated (ie: sourced) ws_b.

So back to your question: there is no special "global ROS path". It is always built up from the paths to any workspaces that are currently active, and if you have multiple overlaying workspaces it will include the union of the pkgs of all those workspaces.

Lastly, how come after catkin_make I can't find my package using rosrun my_package serial_example_node?

If you've created your workspace correctly, have executed source /path/to/your/catkin_ws/devel/setup.bash after running catkin_make and the package is created properly, rosrun should be able to find it. If it doesn't, check that it was actually built. If it was, you may try and run rospack profile, which forces the rebuilding of a cache that some ROS command line tools will use to find your package.

A good way to test things are working is by running rospack find $pkg (where you replace $pkg with the name of your package). If that returns a sane path, things should be ok.

First of all, I don't quite get how a package like this one works when installed (or any ROS package). I checked its CMakeLists.txt file, it only installs headers and an example binary file. Going into cd /opt/ros/kinetic/share/serial there is only package.xml file ...

(more)
edit flag offensive delete link more

Comments

And a note:

the package is installed to my catkin workspace

which is where it should be: packages are never installed into underlying workspaces, only in the one that is currently the top-most one. As your own workspace is in that position, that is where the package ends up.

gvdhoorn gravatar image gvdhoorn  ( 2018-06-27 05:13:07 -0600 )edit

@gvdhoorn, thank you very much for your time putting this excellent answer. I have one more question: when using apt-getinstall, is source installed anywhere in Ubuntu? I understand that they don't have to be in the same directories, I am just curious as to where it's found when #included in .cpp

Hypomania gravatar image Hypomania  ( 2018-06-27 06:10:51 -0600 )edit

@gvdhoorn, P.S, I am able to find the package using rosrun, I was looking at the wrong package.. oops!

Hypomania gravatar image Hypomania  ( 2018-06-27 06:12:03 -0600 )edit

#include is used with headers, and when you ask me about "are sources installed", I interprete that to mean: "are the .cpp files installed". The answer to that last question would be "no". But the headers do get installed, and they are in /opt/ros/$distro/include.

gvdhoorn gravatar image gvdhoorn  ( 2018-06-27 06:22:00 -0600 )edit

@gvdhoorn, in that case, how does the system know where to find function implementations declared in the headers?

Hypomania gravatar image Hypomania  ( 2018-06-27 07:07:09 -0600 )edit

This is no longer a ROS-related question, but a general programming / compilation one. I suggest to ask this sort of question on a more appropriate forum. The compiler never needs the source code for what you ask (or at least, if we consider C/C++).

gvdhoorn gravatar image gvdhoorn  ( 2018-06-27 08:23:11 -0600 )edit

@gvdhoorn, I will do some research, thank you!

Hypomania gravatar image Hypomania  ( 2018-06-27 09:25:16 -0600 )edit

@gvdhoorn, Sorry to ask you the same question again, I am still not sure how ROS packages find function implementations without src files. I did some research and the only examples I found were header-only files, however that's not the case in ROS. Could you provide me with some links to read on?

Hypomania gravatar image Hypomania  ( 2018-06-28 03:54:34 -0600 )edit

Question Tools

2 followers

Stats

Asked: 2018-06-27 04:20:34 -0600

Seen: 10,176 times

Last updated: Jun 27 '18