我试图在cpp中为我的程序构建一个Matlab包装器。该程序使用g2o图形优化外部库。尽管该程序在QT下编译和运行良好,但我没有成功地让它与matlab编译器一起工作。如有任何帮助或建议,将不胜感激。我跟踪了这个帖子@:http://datainfer.wordpress.com/2014/03/28/build-matlab-mex-files-with-cmake/,我的CMakeLists.txt是这样写的:
###########################################################################
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})#编译和终端输出
$ 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!发布于 2015-05-04 11:48:55
问题在艾根图书馆。您不想find_package( Eigen),而只是将EIGEN_INCLUDE_DIRS设置到您已解压的本征路径。同时,从target_link_libraries中删除特征库。特征是一个标头唯一的库,包括它的标头就足够了。
更新: Eigen还在cmake子目录中提供FindEigen3.cmake文件。您可以将此文件复制到源中,并将路径添加到CMAKE_MODULE_PATH中。
https://stackoverflow.com/questions/23083024
复制相似问题