stack-of-tasks / pinocchio

A fast and flexible implementation of Rigid Body Dynamics algorithms and their analytical derivatives
http://stack-of-tasks.github.io/pinocchio/
BSD 2-Clause "Simplified" License
1.78k stars 375 forks source link

c++ compilation error #1574

Closed PangDaCAT closed 2 years ago

PangDaCAT commented 2 years ago

According to the build from source in Installation Procedure,I installed pinocchio 2.6.4 under ubuntu 18.04. But when I run the example,an error occurred. In the function ‘pinocchio::ModelTpl< double, 0, pinocchio::JointCollectionDefaultTpl>& pinocchio::urdf::buildModel<double, 0, pinocchio::JointCollectionDefaultTpl>(std::cxx11::basic_string<char, std::char_traits, std::allocator > const&, pinocchio::ModelTpl<double, 0, pinocchio::JointCollectionDefaultTpl>&, bool)': /usr/local/include/pinocchio/parsers/urdf/model.hxx:394: for'pinocchio::urdf::details::parseRootTree(std::cxx11::basic_string<char, std::char_traits, std::allocator> const&, pinocchio::urdf::details::UrdfVisitorBaseTpl<double, 0>&)' undefined reference

PangDaCAT commented 2 years ago

include

include "pinocchio/parsers/urdf.hpp"

include "pinocchio/algorithm/joint-configuration.hpp"

include "pinocchio/algorithm/kinematics.hpp"

include "pinocchio/algorithm/jacobian.hpp"

include "pinocchio/algorithm/rnea.hpp"

// PINOCCHIO_MODEL_DIR is defined by the CMake but you can define your own directory here.

ifndef PINOCCHIO_MODEL_DIR

define PINOCCHIO_MODEL_DIR "/home/tiansk/WenJian/webots/a1_description"

endif

int main(int argc, char **argv) { //std::cout<<"hello world!"<<std::endl; // You should change here to set up your own URDF file or just pass it as an argument of this example. const std::string urdf_filename = (argc<=1) ? PINOCCHIO_MODEL_DIR + std::string("/urdf/a1.urdf") : argv[1]; pinocchio::Model model; pinocchio::urdf::buildModel(urdf_filename,model); }

jcarpent commented 2 years ago

you need to add the C++11 flags when compiling your file: g++ -O3 -std=c++11 $(pkg-config --cflags --libs pinocchio) test.cpp -o test if you file is name test.cpp

PangDaCAT commented 2 years ago

This doesn't seem to work. try2.cpp:(.text.startup+0x68): to'pinocchio::urdf::details::parseRootTree(std::__cxx11::basic_string<char, std::char_traits, std::allocator> const&, pinocchio::urdf::details::UrdfVisitorBaseTpl<double, 0>&)' undefined reference

jcarpent commented 2 years ago

The reverse then. You need to use std=c++98

PangDaCAT commented 2 years ago

sorry, the same error..

jcarpent commented 2 years ago

Could you check in the history of issues. Similar issues appear with the trouble.

SwonGao commented 1 year ago

hello, have you fixed the issue?

jcarpent commented 1 year ago

Yes, there was no issue on Pinocchio's side. You need to correctly set-up the compilation flags ;)

SwonGao commented 1 year ago

i got /usr/bin/ld: /home/swon/swon_ws/devel/.private/admittance/lib/libtorque_hybridadmittance.so: undefined reference to pinocchio::urdf::details::parseRootTree(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, pinocchio::urdf::details::UrdfVisitorBaseTpl<double, 0>&)' when i catkin build my ROS workspace Actually, I tried add_compile_options(-std=c++11) and set(CMAKE_CXX_FLAGS "-O2 -O3 -std=c++11 -Wall") and c++11 to c++98 in my cmakelist like you said above but they didn't work... And i am Pretty sure the problem is from the line pinocchio::urdf::buildModel(urdf_filename,model); Can you tell me what else should i fix? thank you for your time! @jcarpent I have complete my message

jcarpent commented 1 year ago

Your message is incomplete @SwonGao

GoldenSeaC commented 10 months ago

I resolved this problem(not sure totally) by config the CMakeLists file. After installing the pinocchio lib on PC and add the pkg conig path to the environment variable (.bashrc file) ,I apended the following lines to my cmakelists file

find_package(PkgConfig REQUIRED) pkg_check_modules(PKG_PIN_CONFIG REQUIRED pinocchio)#PKG_PIN_CONFIG is customized name include_directories(${PKG_PIN_CONFIG_INCLUDE_DIRS}) add_executable(overview-urdf overview-urdf.cpp) target_link_libraries(overview-urdf ${PKG_PIN_CONFIG_LIBRARIES})