title: Building Matlab Mex files with CMAKE for g2o library
body: <p>I'm trying to build a Matlab wrapper for my program in cpp. The program uses the <strong>g2o</strong> 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 @: <a href="http://datainfer.wordpress.com/2014/03/28/build-matlab-mex-files-with-cmake/" rel="nofollow">http://datainfer.wordpress.com/2014/03/28/build-matlab-mex-files-with-cmake/</a>
  My CMakeLists.txt reads as follows:</p>
  
  <pre><code>###########################################################################  
  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
  "&lt;CMAKE_CXX_COMPILER&gt; &lt;DEFINES&gt; &lt;FLAGS&gt; -outdir &lt;OBJECT_DIR&gt; -c &lt;SOURCE&gt;; mv &lt;OBJECT_DIR&gt;/$$(basename &lt;SOURCE&gt; .cxx ).o &lt;OBJECT&gt;")
  
  # #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
  "&lt;CMAKE_CXX_COMPILER&gt; -cxx &lt;LINK_FLAGS&gt; &lt;CMAKE_SHARED_LIBRARY_CREATE_CXX_FLAGS&gt; -output &lt;TARGET&gt; &lt;OBJECTS&gt; &lt;LINK_LIBRARIES&gt;")
  
  # #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})
  </code></pre>
  
  <h1>#Compilation and Terminal output</h1>
  
  <pre><code>$ 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!
  </code></pre>