How to integrate external library like ACADO Toolkit with pybind11[QUESTION]
Nobody has claimed this yet.
- Dominant language
- C++
- Stars
- 18k
- Forks
- 2.3k
- Avg merge
- 5d 17h
- Merged PRs (30d)
- 10
Description
I was able to build the library file with the ACADO header files but when I try to import the library it throws segmentation fault.
When I checked what function inside my cpp code was causing segfault, I came to know that ACADO library specific functions were causing segfault.
My CMakeLists.txt file:
`cmake_minimum_required(VERSION 3.0)
project(ur_mpc)
Generate compile_commands.json for clang tools
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
set(CATKIN_PACKAGE_DEPENDENCIES
pybind11_catkin
)
Pybind11 configuration must occur before find_package(catkin)
option(USE_PYBIND_PYTHON_3 "Use python3-compatible python bindings" OFF)
if(USE_PYBIND_PYTHON_3)
set(PYTHON_EXECUTABLE /usr/bin/python3)
set(PYBIND11_PYTHON_VERSION 3.6 CACHE STRING "")
endif(USE_PYBIND_PYTHON_3)
find_package(catkin REQUIRED COMPONENTS
roslib
${CATKIN_PACKAGE_DEPENDENCIES}
)
find_package(Boost REQUIRED COMPONENTS
system
filesystem
)
find_package(PCL 1.7 REQUIRED)
find_package(OpenCV REQUIRED)
find_package(Eigen3 3.3 REQUIRED NO_MODULE)
###################################
catkin specific configuration
###################################
catkin_package(
INCLUDE_DIRS
include
${EIGEN3_INCLUDE_DIRS}
CATKIN_DEPENDS
${CATKIN_PACKAGE_DEPENDENCIES}
LIBRARIES
${PROJECT_NAME}
DEPENDS
Boost
)
###########
Build
###########
include_directories(
include
${EIGEN3_INCLUDE_DIRS}
${Boost_INCLUDE_DIRS}
${catkin_INCLUDE_DIRS}
)
find_package(catkin_simple REQUIRED)
catkin_simple()
ARM NEON flags
if("${CMAKE_HOST_SYSTEM_PROCESSOR}" STREQUAL "armv7l")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -march=armv7-a -mfpu=neon -mfloat-abi=hard -funsafe-math-optimizations")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -march=armv7-a -mfpu=neon -mfloat-abi=hard -funsafe-math-optimizations")
message("enabling ARM neon optimizations")
endif()
flags for speed (should already be enabled by default)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Wextra")
set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -g")
set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -fopenmp -O3")
cs_add_library(ur_mpc_solver_leftarm
externals/qpoases/SRC/Bounds.cpp
externals/qpoases/SRC/Constraints.cpp
externals/qpoases/SRC/CyclingManager.cpp
externals/qpoases/SRC/Indexlist.cpp
externals/qpoases/SRC/MessageHandling.cpp
externals/qpoases/SRC/QProblem.cpp
externals/qpoases/SRC/QProblemB.cpp
externals/qpoases/SRC/SubjectTo.cpp
externals/qpoases/SRC/Utils.cpp
externals/qpoases/SRC/EXTRAS/SolutionAnalysis.cpp
model/ur_robot_leftarm_mpc_export/acado_qpoases_interface.cpp
model/ur_robot_leftarm_mpc_export/acado_integrator.c
model/ur_robot_leftarm_mpc_export/acado_solver.c
model/ur_robot_leftarm_mpc_export/acado_auxiliary_functions.c)
target_include_directories(ur_mpc_solver_leftarm PUBLIC
model/ur_robot_leftarm_mpc_export/
externals/qpoases
externals/qpoases/INCLUDE
externals/qpoases/SRC)
Build python bindings
pybind11_add_module(UR_BIND SHARED
src/ur_mpc_test.cpp
)
add_dependencies(UR_BIND
ur_mpc_solver_leftarm
${catkin_EXPORTED_TARGETS}
)
target_link_libraries(UR_BIND PRIVATE
ur_mpc_solver_leftarm
/home/utsav/catkin_ws/src/ur_mpc/include
${catkin_LIBRARIES}
)
if(USE_PYBIND_PYTHON_3)
unfortunately this appears not to be discoverable yet because the sourcing process assumes python2.7
set_target_properties(UR_BIND
PROPERTIES LIBRARY_OUTPUT_DIRECTORY ${CATKIN_DEVEL_PREFIX}/lib/python3.6/dist-packages/${PROJECT_NAME}
)
else(USE_PYBIND_PYTHON_3)
set_target_properties(UR_BIND
PROPERTIES LIBRARY_OUTPUT_DIRECTORY ${CATKIN_DEVEL_PREFIX}/${CATKIN_PACKAGE_PYTHON_DESTINATION}
)
endif(USE_PYBIND_PYTHON_3)
TODO handle python2/3 case properly
install(TARGETS UR_BIND
ARCHIVE DESTINATION ${CATKIN_PACKAGE_PYTHON_DESTINATION}
LIBRARY DESTINATION ${CATKIN_PACKAGE_PYTHON_DESTINATION}
)
cs_install()
cs_export()
`
It appears that any function defined in the header files of ACADO generated headers causes segfault. If I explicitly add that function in my main cpp file then segfault doesn't occur. I have very basic knowledge of cmake please let me know what is the issue here.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
The issue names CMakeLists.txt, src/ur_mpc_test.cpp, and the ACADO-generated sources; start by reproducing the import segfault and checking how ur_mpc_solver_leftarm is linked into UR_BIND. Compare an ACADO function call with the minimal main.cpp case described. Done requires a reproducible diagnosis and a confirmed fix or closure if the fault is external.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- cmake, cpp, python
- Domain
- api, tooling
- Issue type
- Bug
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 15/100