Closed Czworldy closed 1 year ago
Hi @Czworldy,
We won't be able to help without a way to reproduce your issue. If you can provide a Dockerfile which consistently lead to this, that would be great.
At first glance, you have compiled the library without using the same compilation flags. In particular, if you active vectorization flags (with Eigen), Eigen uses a different malloc
and free
for memory management. This typically the error you obtained.
@nim65s @jcarpent thanks a lot, i will try compiled the library with the same compilation flags.
btw, i found a library i used simply use find_package(pinocchio)
to link pinocchio, let's call it A library,
add_library(
${PROJECT_NAME}
SHARED
${${PROJECT_NAME}_SOURCES}
${${PROJECT_NAME}_HEADERS}
)
target_link_libraries(
${PROJECT_NAME}
PUBLIC
${PINOCCHIO_LIBRARIES}
PRIVATE
${OpenMP_CXX_FLAGS}
)
target_include_directories(
${PROJECT_NAME}
PUBLIC
${EIGEN3_INCLUDE_DIR}
${PINOCCHIO_INCLUDE_DIRS}
$<BUILD_INTERFACE:${PROJECT_SOURCE_DIR}/include>
$<INSTALL_INTERFACE:include>
)
target_compile_options(
${PROJECT_NAME}
PRIVATE
${OpenMP_CXX_FLAGS}
)
When it comes to another library it use PkgConfig to config pinocchio, let's call it B library
find_package(PkgConfig REQUIRED)
pkg_check_modules(pinocchio REQUIRED pinocchio)
add_library(${PROJECT_NAME} ......)
add_dependencies(${PROJECT_NAME}
${catkin_EXPORTED_TARGETS}
)
target_link_libraries(${PROJECT_NAME}
${Boost_LIBRARIES}
${catkin_LIBRARIES}
${pinocchio_LIBRARIES}
)
target_compile_options(${PROJECT_NAME} PUBLIC
${pinocchio_CFLAGS_OTHER}
-Wno-ignored-attributes
-Wno-invalid-partial-specialization
-DPINOCCHIO_URDFDOM_TYPEDEF_SHARED_PTR
-DPINOCCHIO_URDFDOM_USE_STD_SHARED_PTR)
This is just like @jcarpent said, A and B library have different compilation flags, but my project depends on these two library, Does this cause problem? Thanks a lot!
Yes, this is an issue. Both libraries A and B should follow modern CMake practise, and use only target_link_libraries(${PROJECT_NAME} pinocchio::pinocchio)
after a find_package(pinocchio REQUIRED)
, as shown in our https://github.com/stack-of-tasks/pinocchio-minimal/blob/master/CMakeLists.txt example.
Also, there should be no need to involve boost or eigen3, as pinocchio is already re-exporting those.
@nim65s
So the lastest version of pinocchio do not need use pkgconfig
to config it any more? I current use focal, 2.6.20 amd64
version.
In fact, i have no idea what those strange compilation flags means, and i think the way B library used is widely used in project.
Which way is better?
Thank you.
pinocchio export a CMake module, which will be found by find_package(pinocchio REQUIRED)
, and this is way more powerful than pkgconfig.
So if you have a CMake project, you should use pinocchio with CMake, not with pkgconfig.
So, for project A without catkin:
find_package(pinocchio REQUIRED)
add_library(
${PROJECT_NAME}
SHARED
${${PROJECT_NAME}_SOURCES}
${${PROJECT_NAME}_HEADERS}
)
target_link_libraries(
${PROJECT_NAME}
PUBLIC
pinocchio::pinocchio
PRIVATE
${OpenMP_CXX_FLAGS}
)
target_include_directories(
${PROJECT_NAME}
PUBLIC
$<BUILD_INTERFACE:${PROJECT_SOURCE_DIR}/include>
$<INSTALL_INTERFACE:include>
)
target_compile_options(
${PROJECT_NAME}
PRIVATE
${OpenMP_CXX_FLAGS}
)
And for project B with catkin:
find_package(pinocchio REQUIRED)
add_library(${PROJECT_NAME} ......)
add_dependencies(${PROJECT_NAME}
${catkin_EXPORTED_TARGETS}
)
target_link_libraries(${PROJECT_NAME}
${catkin_LIBRARIES}
pinocchio::pinocchio
)
target_compile_options(${PROJECT_NAME} PUBLIC
-Wno-ignored-attributes
-Wno-invalid-partial-specialization)
(an alternative to project B with catkin would be to declare pinocchio as catkin dependency and let catkin handle the CMake for you, but I'm less confident here)
@nim65s Thanks for your advice! i'll try it.
@nim65s Okay i found out that A library compiled with option -march=native
, when remove it, then the seg fault disappear.
But i am curious about how this flags influence Pinocchio
Thanks your guys reply.
:)
This is not specific to pinocchio, but to your compiler, compiler version, and current CPU. Compiling some of your linked libraries with this flag and some without will very often lead to troubles, pinocchio or not.
Hi guys, When i try to build a robot model from a mpc library but i get Segmentation fault, and i use
gdb
to analyse the corefile i got these infomation. That's very strange because this functiongetPinocchioInterfaceFromUrdfModel
works very well in other example, the only thing i have done is that i link a another library which also depends on pinocchio. Do you guys have any idea about this? If you need more infomation, please let me know, i'll reply as fast as possible.