2014-04-15 1 views
1

cpp에서 내 프로그램 용 Matlab 랩퍼를 빌드하려고합니다. 이 프로그램은 g2o 포즈 그래프 최적화 외부 라이브러리를 사용합니다. 이 프로그램은 QT에서 잘 컴파일되고 작동하지만, matlab mex 컴파일러로 작업하는 데 성공하지 못했습니다. 도움이나 제안을 주시면 감사하겠습니다. 나는 포스트 @를 따랐다 다음과 같이 http://datainfer.wordpress.com/2014/03/28/build-matlab-mex-files-with-cmake/ 내 CMakeLists.txt 읽g2o 라이브러리 용 CMAKE를 사용하여 Matlab Mex 파일을 빌드하십시오.

########################################################################### 
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 및 터미널 출력

$ 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! 

답변

0

문제는 고유치 라이브러리입니다. find_package(Eigen)을 원하지 않고 Eigen을 압축 해제 한 경로에 EIGEN_INCLUDE_DIRS을 설정하면됩니다. 또한 Eigen 라이브러리를 target_link_libraries에서 제거하십시오. Eigen은 머리말 만있는 라이브러리이며 헤더 만 있으면 충분합니다.

업데이트 : Eigen도 cmake 하위 디렉토리에서 FindEigen3.cmake 파일을 제공합니다. 이 파일을 소스에 복사하고 경로를 추가하려면 CMAKE_MODULE_PATH