Page 1 of 1

Adding Matlab as external library

Posted: Tue Jun 24, 2014 6:44 pm
by candrastefan
Hello,

I'm trying to build a new functionality that requires loading Matlab's .MAT file and using Matlab libraries. However, I have a linker problem during compilation process.

Code: Select all

[ 45%] Linking CXX executable CloudCompare
Built target QHPR_PLUGIN
[ 47%] Built target QPOISSON_RECON_PLUGIN
[ 54%] Built target QSRA_PLUGIN
[ 56%] Built target QRANSAC_SD_PLUGIN
../CC/libCC_CORE_LIB.so: undefined reference to `matOpen'
collect2: error: ld returned 1 exit status
My Matlab libraries (libmat.so, libmx.so, etc) are in this folder: /usr/sww/pkg/matlab-R2014a/bin/glnxa64. I suppose I should add this to the CMakeExternalLibs.cmake in trunk. But I don't know how to do it correctly. This is what I added to CMakeExternalLibs.cmake:

Code: Select all

# ------------------------------------------------------------------------------
# MATLAB
# ------------------------------------------------------------------------------
find_package ( Matlab REQUIRED )
if( MATLAB_FOUND )
	set( MATLAB_ROOT_PATH CACHE PATH "Matlab root directory (i.e. where the 'bin' folder lies)" )
	include( ${MATLAB_USE_FILE} )
	include_directories(${MATLAB_INCLUDE_DIR})
	list( APPEND EXTERNAL_LIBS_INCLUDE_DIR ${MATLAB_INCLUDE_DIR} )
	list( APPEND EXTERNAL_LIBS_LIBRARIES ${QT_LIBRARIES} )
else()
	message( SEND_ERROR "Matlab required, but not found with 'find_package()'" )
endif()
However, the result is that:

Code: Select all

CMake Error at CMakeExternalLibs.cmake:105 (message):
  Matlab required, but not found with 'find_package()'
Please help me with this. Thanks in advance.

Re: Adding Matlab as external library

Posted: Tue Jun 24, 2014 9:27 pm
by daniel
I guess that QT_LIBRARIES is not the libraries you want to append here ;)

Code: Select all

  list( APPEND EXTERNAL_LIBS_LIBRARIES ${QT_LIBRARIES} ) 
Anyway I don't think that Matlab provides a CMake script for detecting the right include and library directories. You should look at how we handle this "manually" in the LiblasSupport.cmake or FBXSupport.cmake files (i.e. the user has to point manually to the right include directory and to the right library file(s)).