Question

I'm trying to build a Matlab wrapper for my program in cpp. The program uses the g2o pose graph optimisation external library. Though the program compiles and functions well under QT, I am not successful to get it working with the the matlab mex compiler. Any help or suggestions will be highly appreciated. I have followed the post @: http://datainfer.wordpress.com/2014/03/28/build-matlab-mex-files-with-cmake/ My CMakeLists.txt reads as follows:

###########################################################################  
cmake_minimum_required(VERSION 2.8)

project(mex_g2o_test)
SET(CMAKE_BUILD_TYPE Release)

############################################
SET( CMAKE_CXX_COMPILER mex )
SET( CMAKE_C_COMPILER   mex )

# #Suffix and Prefix of the output target file
SET( CMAKE_SHARED_LIBRARY_SUFFIX .mexa64 )  # set suffix to .mexa64
SET( CMAKE_SHARED_LIBRARY_PREFIX )      # remove the "lib" prefix

# #Variables controlling the build-phrase
SET( CMAKE_CXX_FLAGS "-cxx -largeArrayDims CXXFLAGS='$$CXXFLAGS -std=c++11'" )
SET( CMAKE_SHARED_LIBRARY_CXX_FLAGS )       # remove the -fPIC option. mex does not  accept the "-fPIC" option

SET( CMAKE_CXX_COMPILE_OBJECT
"<CMAKE_CXX_COMPILER> <DEFINES> <FLAGS> -outdir <OBJECT_DIR> -c <SOURCE>; mv <OBJECT_DIR>/$$(basename <SOURCE> .cxx ).o <OBJECT>")

# #Variables controlling the linking-phase
SET( CMAKE_SHARED_LIBRARY_CREATE_CXX_FLAGS )    # remove -shared options. mex does not accept the "-shared" option

SET(
CMAKE_CXX_CREATE_SHARED_LIBRARY
"<CMAKE_CXX_COMPILER> -cxx <LINK_FLAGS> <CMAKE_SHARED_LIBRARY_CREATE_CXX_FLAGS> -output <TARGET> <OBJECTS> <LINK_LIBRARIES>")

# #Variables controlling the installation RPATH
SET( CMAKE_INSTALL_RPATH "\$ORIGIN" )
# #CMake will reset RPATH at the installation phase, so we need to specify CMAKE_INSTALL_RPATH

MESSAGE( STATUS "mex.cmake is loaded.\n" )

################################################
SET(CMAKE_MODULE_PATH ${g2o_test_SOURCE_DIR}/cmake)

find_package(Eigen 3.0 REQUIRED)
find_package(G2O REQUIRED)
find_package(CSparse REQUIRED)
find_package(CHOLMOD REQUIRED)
include_directories(${G2O_INCLUDE_DIR})
include_directories(${CSPARSE_INCLUDE_DIR})
include_directories(${EIGEN_INCLUDE_DIRS})

SET(G2O_LIBRARIES  ${G2O_CORE_LIBRARY} ${G2O_STUFF_LIBRARY} ${G2O_SOLVER_CSPARSE} ${G2O_SOLVER_CSPARSE_EXTENSION} ${G2O_TYPES_SLAM3D} ${G2O_TYPES_SLAM2D} ${CSPARSE_LIBRARIES} ${CHOLMOD_LIBRARIES} ${G2O_SOLVER_CHOLMOD} cxsparse blas)


ADD_LIBRARY( mex_g2o_test SHARED mex_g2o_test.cpp )
TARGET_LINK_LIBRARIES(mex_g2o_test ${G2O_LIBRARIES} ${EIGEN_LIBRARIES})

#Compilation and Terminal output

$ cmake ../
-- The C compiler identification is GNU 4.7.2
-- The CXX compiler identification is GNU 4.7.2
-- Check for working C compiler: /usr/lib64/ccache/gcc
-- Check for working C compiler: /usr/lib64/ccache/gcc -- works
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Check for working CXX compiler: /usr/lib64/ccache/c++
-- Check for working CXX compiler: /usr/lib64/ccache/c++ -- works
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- mex.cmake is loaded.

CMake Error at CMakeLists.txt:38 (find_package):
By not providing "FindEigen.cmake" in CMAKE_MODULE_PATH this project has
asked CMake to find a package configuration file provided by "Eigen", but
CMake did not find one.

Could not find a package configuration file provided by "Eigen" (requested
version 3.0) with any of the following names:

EigenConfig.cmake
eigen-config.cmake

Add the installation prefix of "Eigen" to CMAKE_PREFIX_PATH or set
"Eigen_DIR" to a directory containing one of the above files.  If "Eigen"
provides a separate development package or SDK, be sure it has been
installed.


-- Configuring incomplete, errors occurred!
Was it helpful?

Solution

The problem is in the Eigen library. You don't want to find_package( Eigen), instead just set EIGEN_INCLUDE_DIRS to the path where you have unpacked Eigen. Also, remove Eigen libs from target_link_libraries. Eigen is a header only library, including its headers is enough.

Update: Eigen also ships FindEigen3.cmake file in cmake subdirectory. You could copy this file to your sources and add path to is to CMAKE_MODULE_PATH

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top