Attention

This is older information related to ROS2 Humble. Newer versions, such as Jazzy, are part of the ongoing versions of this tutorial.

Install a CMake package without sudo privileges

To install a CMake package or library without sudo privileges, we need to define a directory to which we have access. For instance, in ~/.

Create a custom folder

In this tutorial, we are going to create a custom folder ~/opt containing the folders lib and include. This will be our directory to install all our CMake packages.

Run the following commands,

cd ~/
mkdir -p opt && cd opt
mkdir -p include
mkdir -p lib

Then, we update the LD_LIBRARY_PATH, LIBRARY_PATH, and CPATH in ~/.bashrc.

Do the following just once, so that all terminal windows automatically source this new workspace for you.

echo "# Update the environment variable LD_LIBRARY_PATH to include ~/opt/lib, as instructed in https://ros2-tutorial.readthedocs.io" >> ~/.bashrc
echo "export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:~/opt/lib" >> ~/.bashrc

echo "# Update the environment variable LIBRARY_PATH to include ~/opt/lib, as instructed in https://ros2-tutorial.readthedocs.io" >> ~/.bashrc
echo "export LIBRARY_PATH=$LIBRARY_PATH:~/opt/lib" >> ~/.bashrc

echo "# Update the environment variable CPATH to include ~/opt/include, as instructed in https://ros2-tutorial.readthedocs.io" >> ~/.bashrc
echo "export CPATH=$CPATH:~/opt/include" >> ~/.bashrc

source ~/.bashrc

Install a CMake package

To install a CMake package, we set the CMAKE_INSTALL_PREFIX:PATH flag with our custom folder (/home/USERNAME/opt)

cmake -DCMAKE_INSTALL_PREFIX:PATH=~/opt ..
make
make install

Example: Installing qpOASES

This example shows how to build and install the qpOASES to be used in your CMake project.

Note

Check the official qpOASES documentation for more details.

Warning

This example assumes you have git, CMake, Eigen, and a C++ compiler installed in your GNU/Linux distribution.

To install qpOASES as a shared library, we use the instructions provided by the DQ Robotics in cpp-interface-qpoases specifying the installation directory.

cd ~/Downloads
git clone https://github.com/coin-or/qpOASES.git
cd qpOASES
sed -i -e 's/option(BUILD_SHARED_LIBS "If ON, build shared library instead of static" OFF)/option(BUILD_SHARED_LIBS "If ON, build shared library instead of static" ON)/g' CMakeLists.txt
mkdir build
cd build
cmake .. -DCMAKE_INSTALL_PREFIX:PATH=~/opt
make
make install