简体   繁体   中英

Translate a g++ command for terminal compilation to CMakeLists.txt

I am a beginner in CMake and I am trying to follow a tutorial for a project I am currently working on. The tutorial can be found here: https://gepettoweb.laas.fr/doc/stack-of-tasks/pinocchio/master/doxygen-html/index.html#OverviewInstall (Part: More complex example with C++ and Python).
At some point, this tutorial provides a g++ command for compilation, but because of the specifities of my project, I can't use the terminal and have to translate this command to a CMakeLists.txt. Here is the command:

g++ -I /path/to/eigen -I /path/to/pinocchio/include/ -DPINOCCHIO_URDFDOM_TYPEDEF_SHARED_PTR -DPINOCCHIO_WITH_URDFDOM overview-urdf.cpp -lboost_system -lurdfdom_model -o overview-urdf

My problem concerns the second part of the command, starting from the flags. I added my executable and the two first path, and then I wrote this:

target_compile_definitions(overview-urdf PUBLIC PINOCCHIO_URDFDOM_TYPEDEF_SHARED_PTR PINOCCHIO_WITH_URDFDOM)
target_link_libraries(overview-urdf /usr/lib/x86_64-linux-gnu/libboost_system.so)
target_link_libraries(overview-urdf /opt/ros/foxy/lib/liburdfdom_world.so)

But if I try to build everything, the compilation fails and indicates an error in a file from the Pinocchio library I use (a file that I did not modify and on which there is no git issue declared). The functions in which a problem is indicated seem to all be concerned by the PINOCCHIO_URDF_SHARED_PTR, thus I expect that there is a problem with how I inserted the flags in my CMakeLists.

I hope that it is clear enough. Thanks in advance!

EDIT: extract of the error message

In file included from /opt/openrobots/include/pinocchio/parsers/urdf.hpp:261:0,
                 from testPinocchio.cpp:1:
/opt/openrobots/include/pinocchio/parsers/urdf/geometry.hxx:256:7: error: template-id ‘getLinkGeometry<urdf::Collision>’ for ‘urdf::CollisionConstSharedPtr pinocchio::urdf::details::getLinkGeometry(urdf::LinkConstSharedPtr)’ does not match any template declaration
       getLinkGeometry< ::urdf::Collision>(const ::urdf::LinkConstSharedPtr link)
       ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/opt/openrobots/include/pinocchio/parsers/urdf/geometry.hxx:252:7: note: candidate is: template<class T> boost::shared_ptr<const T> pinocchio::urdf::details::getLinkGeometry(urdf::LinkConstSharedPtr)
       getLinkGeometry(const ::urdf::LinkConstSharedPtr link);

And here is the corresponding code extract; coming from the corresponding file on the git of Pinocchio:

template<typename T>
      inline PINOCCHIO_URDF_SHARED_PTR(const T)
      getLinkGeometry(const ::urdf::LinkConstSharedPtr link);

      template<>
      inline ::urdf::CollisionConstSharedPtr
      getLinkGeometry< ::urdf::Collision>(const ::urdf::LinkConstSharedPtr link)
      {
        return link->collision;
      }

      template<>
      inline ::urdf::VisualConstSharedPtr
      getLinkGeometry< ::urdf::Visual>(const ::urdf::LinkConstSharedPtr link)
      {
        return link->visual;
      }

Try:

add_executable(overview-urdf overview-urdf.cpp)
target_include_directories(overview-urdf PUBLIC
   /path/to/eigen
   /path/to/pinocchio/include/
)
target_compile_definitions(overview-urdf PUBLIC 
   PINOCCHIO_URDFDOM_TYPEDEF_SHARED_PTR
   PINOCCHIO_WITH_URDFDOM
)
target_link_libraries(overview-urdf PUBLIC 
      boost_system
      urdfdom_model
)

After trying the syntax proposed by KamilCuk, I got the same error. I managed to use the given g++ compilation command "artificially" in my architecture, and it led to the same error than before... Thus, I think that the error does not come from the CMakeLists itself.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM