I would like to write a CMakeLists.txt
such that CMake writes a Visual Studio 2010 (64 bit) solution file to build a mex function for MATLAB R2011a (64 bit) from C++ code example.cxx
.
- I do not want to use MATLAB's compiler wrapper
mex
but set up the Visual Studio solution file such that Visual C++ links the relevant MATLAB libraries. example.cxx
has no dependencies except for the MATLAB libraries that are necessary for mex files.- CMake 2.8.7 is set up correctly such that it uses the 64 bit generator for Visual Studio 2010.
The essence of what I am doing right now is
find_package(Matlab)
add_library(example STATIC example.cxx)
target_link_libraries(example ${MATLAB_LIBRARIES})
Neither the compiler nor the linker issues any errors. I install the output example.lib
under the name example.mexw64
in a directory in MATLAB's path. When I call example
from MATLAB, I get the error message
??? Invalid MEX-file
'C:\...\example.mexw64':
C:\...\example.mexw64 is not a valid Win32 application.
Any suggestions are welcome!