1

My goal is to install a library (rbdl-orb) on my Mac and import the library in a C++ program.

My first attempt was to clone the library and run the included example directly. The program "example.cc" starts with the following two lines:

#include <iostream>
#include <rbdl/rbdl.h>

The CMake file follows:

PROJECT (RBDLEXAMPLE CXX)

CMAKE_MINIMUM_REQUIRED(VERSION 3.0)

# We need to add the project source path to the CMake module path so that
# the FindRBDL.cmake script can be found.
LIST( APPEND CMAKE_MODULE_PATH ${PROJECT_SOURCE_DIR} )


SET(CUSTOM_RBDL_PATH "" CACHE PATH "Path to specific RBDL Installation")
# Search for the RBDL include directory and library
FIND_PACKAGE (RBDL REQUIRED)
FIND_PACKAGE (Eigen3 3.0.0 REQUIRED)

# Add the include directory to the include paths
INCLUDE_DIRECTORIES ( ${RBDL_INCLUDE_DIR} ${EIGEN3_INCLUDE_DIR} )

# Create an executable
ADD_EXECUTABLE (example example.cc)

# And link the library against the executable
TARGET_LINK_LIBRARIES (example
    ${RBDL_LIBRARY}
    )

Typing "make example" yields the following error:

c++     example.cc   -o example
example.cc:10:10: fatal error: 'rbdl/rbdl.h' file not found
#include <rbdl/rbdl.h>
         ^~~~~~~~~~~~~
1 error generated.
make: *** [example] Error 1

I am guessing that there are steps needed to install the library, such that the C++ compiler knows where to look for the files when it sees the command "import". The library's GitHub notes that the package is available for installation through vcpkg.

I installed vcpkg by following the instructions. Then, I built the library by typing "vcpkg install rbdl" in a Terminal. Typing "vcpkg list" in the working directory shows that the library appears to be installed:

(base) my_name@my_name-MacBook-Pro current_directory % vcpkg list
eigen3:arm64-osx                                   3.4.0#2          C++ template library for linear algebra: matrice...
rbdl:arm64-osx                                     2.6.0#2          Rigid Body Dynamics Library
vcpkg-cmake-config:arm64-osx                       2022-02-06       
vcpkg-cmake:arm64-osx                              2022-04-07

Unfortunately, typing "make example" again yields the following error:

c++     example.cc   -o example
example.cc:10:10: fatal error: 'rbdl/rbdl.h' file not found
#include <rbdl/rbdl.h>
         ^~~~~~~~~~~~~
1 error generated.
make: *** [example] Error 1

The error suggests that the C++ compiler is not aware of the location where the library was installed.

How can I correctly install the library and import it in my C++ program?

  • Can you show your CMakeLists.txt for your application? Did you use the toolchain file? Or are you not using CMake with your code? – drescherjm Apr 12 '22 at 17:01
  • Your quick response is appreciated! The post has been edited to show the CMakeLists.txt. I am not sure what a toolchain file, will look into it. – Farzan Beroz Apr 12 '22 at 17:05
  • Related to the toolchain file: [https://github.com/microsoft/vcpkg#vcpkg-with-visual-studio-cmake-projects](https://github.com/microsoft/vcpkg#vcpkg-with-visual-studio-cmake-projects) – drescherjm Apr 12 '22 at 17:11
  • I am not even sure that the correct Makefile is being used looking at the output. You may want to enable verbose: [https://unix.stackexchange.com/questions/574497/is-there-a-way-to-make-cmakelists-txt-more-verbose-for-compilation](https://unix.stackexchange.com/questions/574497/is-there-a-way-to-make-cmakelists-txt-more-verbose-for-compilation) – drescherjm Apr 12 '22 at 17:16
  • Update: reinstalled the entire library, this time using "sudo" to install with system privileges, and it managed to compile the header. – Farzan Beroz Apr 13 '22 at 17:29

2 Answers2

0

I've no certitude this is the best way to proceed, and I'm assuming mac and linux are similar here...

I guess you could search for the location of the rgbd.cmake and append it to the CMAKE_MODULE_PATH variable. to have a very fast search I'd used ripgrep that way :

$ rg --files / 2>/dev/null|rg rgbd.*\\.cmake$
... expect to chose a path from the outputed ones.

let me know if you have an outpput at all. If so, then add it to the cmakelist:

list(APPEND CMAKE_MODULE_PATH "the path to rgbd.cmake")

hope that helps.

Zoyolin
  • 25
  • 5
0

Reinstalled the library using "sudo" and started using the vcpkg installation and made the following change to the CMake file:

SET(CMAKE_CXX_STANDARD 11)

After these changes, the library is running correctly.