Including DART as a dependent library

Hey there,

I am very new to CMake and package-based projects in general. I’ve been able to install DART from source previously and run the tutorials just fine, but now I would like to try to use DART as a library in a separate project. I understand that I should be able to use CMake to include DART to do this, but haven’t found out how this would work. If there is an easy example for how to do this, please let me know, otherwise I’ll share what I’ve tried and that can perhaps show where I’m going wrong.

So far I’ve followed the instructions to install DART with Ubuntu packages and created a simple directory external to DART. This directory just contains a build directory, a CMakeLists.txt file, and a main.cpp that has the contents of the finished pendulum tutorial in it. The CMakeLists.txt file that I have so far is:

cmake_minimum_required(VERSION 3.5.1)
project(mpc-project)

set(CMAKE_INCLUDE_CURRENT_DIR ON)
set(CMAKE_AUTOMOC ON)

set (CMAKE_CXX_STANDARD 11)
set(CMAKE_CXX_FLAGS "-g -Wall")

find_package(DART 6.6.0 REQUIRED COMPONENTS utils-urdf gui CONFIG)
find_package(Qt5Core)

add_executable(${PROJECT_NAME} "main.cpp")

target_link_libraries(${PROJECT_NAME} PUBLIC dart dart-utils-urdf dart-gui Qt5::Core)

This is my best guess from my extremely limited knowledge of CMake and some of the previously asked questions on this forum. When I run make I get a whole wall of errors with things like:

/usr/include/boost/math/constants/constants.hpp: In static member function ‘static constexpr T boost::math::constants::detail::constant_twothirds<T>::get(const mpl_::int_<5>&)’:
/usr/include/boost/math/constants/constants.hpp:279:3: error: unable to find numeric literal operator ‘operator""Q’
   BOOST_DEFINE_MATH_CONSTANT(twothirds, 6.666666666666666666666666666666666666e-01, "6.6666666666666666666666666666
   ^
/usr/include/boost/math/constants/constants.hpp:279:3: note: use -std=gnu++11 or -fext-numeric-literals to enable more built-in suffixes

or various errors that certain dart functions were not declared in the scope. Clearly these are the symptoms of not correctly building/linking the project, so that’s where I could use some aid.

Thanks!

The CMakeLists.txt looks good to me. It seems it has something to do with Boost version or missing compile options for the Boost’s numeric literal operator. I would try:

  • build your project without Qt5Core to see if this is actually the issue of DART
  • add the compile options to your target following the suggestions in the error message like:
target_compile_options(${PROJECT_NAME} PUBLIC -fext-numeric-literals)

Removing Qt5Core didn’t seem to make a difference, adding the compile options seemed to clear the errors about boost but the other DART-related errors remain. There are too many to copy them all, but a few for context are:

In file included from /usr/include/dart/dynamics/CompositeNode.hpp:117:0,
                 from /usr/include/dart/dynamics/detail/ShapeNode.hpp:38,
                 from /usr/include/dart/dynamics/ShapeNode.hpp:39,
                 from /usr/include/dart/dynamics/Skeleton.hpp:43,
                 from /usr/include/dart/dynamics/BodyNode.hpp:53,
                 from /usr/include/dart/collision/detail/CollisionGroup.hpp:38,
                 from /usr/include/dart/collision/CollisionGroup.hpp:540,
                 from /usr/include/dart/collision/collision.hpp:7,
                 from /usr/include/dart/dart.hpp:37,
                 from /home/joe/mpc-project/main.cpp:32:
/usr/include/dart/dynamics/detail/CompositeNode.hpp:77:37: error: expected primary-expression before ‘>’ token
   return std::make_unique<Properties>(
                                     ^
/home/joe/mpc-project/main.cpp: At global scope:
/home/joe/mpc-project/main.cpp:56:1: error: expected class-name before ‘{’ token
 {
 ^
/home/joe/mpc-project/main.cpp:172:8: error: ‘void MyWindow::keyboard(unsigned char, int, int)’ marked ‘override’, but does not override
   void keyboard(unsigned char key, int x, int y) override
        ^
/home/joe/mpc-project/main.cpp:250:8: error: ‘void MyWindow::timeStepping()’ marked ‘override’, but does not override
   void timeStepping() override
        ^
/home/joe/mpc-project/main.cpp: In constructor ‘MyWindow::MyWindow(dart::simulation::WorldPtr)’:
/home/joe/mpc-project/main.cpp:65:19: error: ‘setWorld’ was not declared in this scope
     setWorld(world);
                   ^
/home/joe/mpc-project/main.cpp: In member function ‘void MyWindow::addConstraint()’:
/home/joe/mpc-project/main.cpp:161:5: error: ‘mWorld’ was not declared in this scope
     mWorld->getConstraintSolver()->addConstraint(mBallConstraint);
     ^
/home/joe/mpc-project/main.cpp: In member function ‘void MyWindow::removeConstraint()’:
/home/joe/mpc-project/main.cpp:167:5: error: ‘mWorld’ was not declared in this scope
     mWorld->getConstraintSolver()->removeConstraint(mBallConstraint);
     ^
/home/joe/mpc-project/main.cpp: In member function ‘void MyWindow::keyboard(unsigned char, int, int)’:
/home/joe/mpc-project/main.cpp:246:9: error: ‘SimWindow’ has not been declared
         SimWindow::keyboard(key, x, y);

I cannot infer what’s the cause from the provided error messages. Could you share the entire error messages and the main.cpp using gist?

Here’s the gist: https://gist.github.com/jcnorby/fdebf186f8ac9480a8eebc49f53059e2

Also just to be sure we’re using the same build setup, here’s a github repo with the simplest example of my code: https://github.com/jcnorby/DART-Library-Example

Thank you for sharing the code and build log. It was the C++ standard version and the namespace of SimWindow. Below diff should fix the build:

diff --git a/CMakeLists.txt b/CMakeLists.txt
index 716fb6c..ddcab40 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -4,7 +4,7 @@ project(mpc-project)
 set(CMAKE_INCLUDE_CURRENT_DIR ON)
 set(CMAKE_AUTOMOC ON)
 
-set (CMAKE_CXX_STANDARD 11)
+set (CMAKE_CXX_STANDARD 14)
 set(CMAKE_CXX_FLAGS "-g -Wall")
 
 find_package(DART 6.6.0 REQUIRED COMPONENTS utils-urdf gui CONFIG)
@@ -12,4 +12,4 @@ find_package(DART 6.6.0 REQUIRED COMPONENTS utils-urdf gui CONFIG)
 add_executable(${PROJECT_NAME} "main.cpp")
 
 target_link_libraries(${PROJECT_NAME} PUBLIC dart dart-utils-urdf dart-gui)
-target_compile_options(${PROJECT_NAME} PUBLIC -fext-numeric-literals)
\ No newline at end of file
+target_compile_options(${PROJECT_NAME} PUBLIC -fext-numeric-literals)
diff --git a/main.cpp b/main.cpp
index 292cca9..9f7dfb1 100644
--- a/main.cpp
+++ b/main.cpp
@@ -52,7 +52,7 @@ const double delta_damping = 1.0;
 using namespace dart::dynamics;
 using namespace dart::simulation;
 
-class MyWindow : public dart::gui::SimWindow
+class MyWindow : public dart::gui::glut::SimWindow
 {
 public:
 
@@ -461,4 +461,4 @@ int main(int argc, char* argv[])
   glutInit(&argc, argv);
   window.initWindow(640, 480, "Multi-Pendulum Tutorial");
   glutMainLoop();
-}
\ No newline at end of file
+}

As a note, the GLUT based examples are deprecated. Please consider using OpenSceneGraph based examples (e.g., biped_stand).

Ah, it works! Thanks!

1 Like