I am new in CMake but I want to use pybind11 to to create python library of my cpp code. My cpp code contain gtsam and ceres library. in creating CMakeLists file I used target_link_libraries to add my library but I have an error when I use Ceres::ceres. like this:
target_link_libraries(libscampi_ks
Ceres::ceres
gtsam
# ${GTSAM_LIBRARIES}
# ${CERES_LIBRARIES}
)
Even I used ${CERES_LIBRARIES} but in both I have this error:
CMake Error at /usr/local/lib/cmake/Ceres/CeresTargets.cmake:61 (set_target_properties):
The link interface of target "Ceres::ceres" contains:
SuiteSparse::Partition
but the target was not found. Possible reasons include:
* There is a typo in the target name.
* A find_package call is missing for an IMPORTED target.
* An ALIAS target is missing.
Call Stack (most recent call first):
/usr/local/lib/cmake/Ceres/CeresConfig.cmake:272 (include)
CMakeLists.txt:18 (find_package)
I installed ceres correctly and my cpp code also run correctly but today I find this problem. I don't know if I have a problem in my CMakeLists file. (furthere more if I cmake.. and make this file without Ceres::ceres in target_link_libraries it run but in using python module I give this error: "double free or corruption (out) Aborted (core dumped)" that I think maybe it is beacause of not using Ceres::ceres in my target_link_libraries)
thanks anyone if can help me.
Also here is my full version of my CMakeLists file:
cmake_minimum_required(VERSION 3.26.3)
project(scampi_factor_graph_solver)
# find_package (PythonLibs COMPONENTS)
# include_directories(/usr/include/python3.8/)
# set(GTSAM_DIR /home/mohammad/gtsam)
set (CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/cmake")
set(CMAKE_CXX_STANDARD 17)
add_compile_options(-std=c++17)
#SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -mfma")
SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -mavx2 -mfma")
set(CMAKE_POSITION_INDEPENDENT_CODE ON)
include(cotire)
include(GNUInstallDirs)
find_package(Ceres REQUIRED)
# find_package(Ceres REQUIRED COMPONENTS EigenSparse SparseLinearAlgebraLibrary LAPACK SuiteSparse SchurSpecializations)
find_package(Eigen3 REQUIRED)
find_package(GTest REQUIRED)
# Find the manif library: https://github.com/artivis/manif/blob/devel/docs/pages/cpp/Quick-start.md
find_package(manif REQUIRED)
###### GTSAM STUFF STARTS HERE
# Include GTSAM CMake tools
find_package(GTSAMCMakeTools)
if(GTSAMCMakeTools_FOUND)
message(STATUS "GTSAMCMakeTools FOUND ${GTSAM_VERSION}")
else()
message(STATUS "GTSAMCMakeTools Not Found")
endif()
#include(GtsamBuildTypes) # Load build type flags and default to Debug mode
#include(GtsamTesting) # Easy functions for creating unit tests and scripts
#include(GtsamMatlabWrap) # Automatic MATLAB wrapper generation
# Ensure that local folder is searched before library folders
#include_directories(BEFORE "${PROJECT_SOURCE_DIR}")
###################################################################################
# Find GTSAM components
find_package(GTSAM REQUIRED) # Uses installed package
include_directories(${GTSAM_INCLUDE_DIR})
if(GTSAM_FOUND)
message(STATUS "Found GTSAM ${GTSAM_VERSION}")
else()
message(STATUS "GTSAM Not Found")
endif()
###################################################################################
# Build static library from common sources
#set(CONVENIENCE_LIB_NAME ${PROJECT_NAME})
#add_library(${CONVENIENCE_LIB_NAME} STATIC include/car/car_lib.h src/car_lib.cpp)
#target_link_libraries(${CONVENIENCE_LIB_NAME} gtsam)
find_package(Boost REQUIRED)
find_package(TBB REQUIRED)
###### GTSAM STUFF ENDS HER
include_directories(include
lib/include
gtsam
${EIGEN3_INCLUDE_DIRS}
${manif_INCLUDE_DIRS}
${GTSAM_INCLUDE_DIR}
)
add_library(libscampi_ks
lib/src/scampi.cpp
)
target_link_libraries(libscampi_ks
Ceres::ceres
gtsam
# ${GTSAM_LIBRARIES}
# ${CERES_LIBRARIES}
)
cotire(libscampi_ks)
add_subdirectory(pybind11)
pybind11_add_module(scampi_fg src/main.cpp)
target_link_libraries(scampi_fg PRIVATE
Ceres::ceres
gtsam
libscampi_ks
${SCAMPI_SOLVER_LIBS}
# ${GTSAM_LIBRARIES}
# ${CERES_LIBRARIES}
)
target_compile_definitions(scampi_fg
PRIVATE VERSION_INFO=${VERSION_INFO})