Now when you make a mex file with cmake it will only try to link to the BLAS

and LAPACK that comes with MATLAB since trying to use any other BLAS or LAPACK
generally makes MATLAB unstable.
This commit is contained in:
Davis King 2016-02-04 09:19:13 -05:00
parent 36fdfe6802
commit 6886042c8e
3 changed files with 29 additions and 8 deletions

View File

@ -23,6 +23,23 @@ SET(lapack_found 0)
if (UNIX)
message(STATUS "Searching for BLAS and LAPACK")
if (BUILDING_MATLAB_MEX_FILE)
find_library(MATLAB_BLAS_LIBRARY mwblas PATHS ${MATLAB_LIB_FOLDERS} )
find_library(MATLAB_LAPACK_LIBRARY mwlapack PATHS ${MATLAB_LIB_FOLDERS} )
if (MATLAB_BLAS_LIBRARY AND MATLAB_LAPACK_LIBRARY)
add_subdirectory(external/cblas)
set(blas_libraries ${MATLAB_BLAS_LIBRARY} cblas )
set(lapack_libraries ${MATLAB_LAPACK_LIBRARY} )
set(blas_found 1)
set(lapack_found 1)
message(STATUS "Found MATLAB's BLAS and LAPACK libraries")
endif()
# Don't try to link to anything other than MATLAB's own internal blas
# and lapack libraries because doing so generally upsets MATLAB. So
# we just end here no matter what.
return()
endif()
include(CheckTypeSize)
check_type_size( "void*" SIZE_OF_VOID_PTR)
@ -61,14 +78,8 @@ if (UNIX)
set(lapack_found 1)
set(found_intel_mkl 1)
message(STATUS "Found Intel MKL BLAS/LAPACK library")
if (BUILDING_MATLAB_MEX_FILE)
message(STATUS "\n!!!! Don't forget to set the BLAS_VERSION and LAPACK_VERSION environment variables to !!!!\n!!!! ${blas_libraries} so MATLAB doesn't explode when you run this mex file !!!!\n")
endif()
endif()
if (BUILDING_MATLAB_MEX_FILE)
return()
endif()
if (NOT found_intel_mkl)
# Search for the needed libraries from the MKL. This time try looking for a different

View File

@ -67,7 +67,17 @@ INCLUDE(InstallRequiredSystemLibraries)
MACRO(add_mex_function name )
ADD_LIBRARY(${name} MODULE ${name}.cpp )
ADD_LIBRARY(${name} MODULE ${name}.cpp )
if (UNIX)
# Doing this prevents our mex function from exporting any symbols
# other than mexFunction(). This sometimes doesn't matter but sometimes
# avoids causing errors or otherwise bad behavior in MATLAB.
if (DEFINED ENV{MATLAB_HOME})
set_target_properties(${name} PROPERTIES LINK_FLAGS "-Wl,--version-script,$ENV{MATLAB_HOME}/extern/lib/glnxa64/mexFunction.map")
else()
set_target_properties(${name} PROPERTIES LINK_FLAGS "-Wl,--version-script,${MATLAB_HOME}/extern/lib/glnxa64/mexFunction.map")
endif()
endif()
# Change the output file extension to a mex extension.
if (WIN32)

View File

@ -43,7 +43,7 @@ namespace dlib
namespace lapack
{
// stuff from f2c used to define what exactly is an integer in fortran
#if defined(__alpha__) || defined(__sparc64__) || defined(__x86_64__) || defined(__ia64__)
#if (defined(__alpha__) || defined(__sparc64__) || defined(__x86_64__) || defined(__ia64__)) && !defined(MATLAB_MEX_FILE)
typedef int integer;
typedef unsigned int uinteger;
#else