问题描述
我想编写一个的CMakeLists.txt
这样的CMake写一个Visual Studio 2010(64位)解决方案文件建立一个MEX功能MATLAB R2011a(64位)从C + + code example.cxx
。
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
.
- 我不想使用MATLAB的编译器包装
MEX
,但设置了Visual Studio解决方案文件,这样的Visual C ++链接相关的MATLAB库。 -
example.cxx
有除了MATLAB库所必需的MEX文件没有依赖关系。 - 的CMake 2.8.7设置正确,这样它采用了64位发生器的Visual Studio 2010。
- 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})
无论是编译器和链接器发出任何错误。我安装的输出 example.lib
下在MATLAB的路径的目录名称 example.mexw64
。当我打电话例如
从MATLAB,我得到错误信息
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!
推荐答案
我有rel="nofollow">这个链接同样的问题,是非常有益的(也可作为如何使用一个很好的例子 ITK 在MATLAB MEX文件顺便说一句)。我觉得对于你的情况,你需要添加链接标记/输出:mexFunction
您的CMakeLists.txt
文件。下面的例子:
I had the same problem and this link was very helpful (also serves as a nice example of how to use ITK in a MATLAB MEX file btw). I think for your case, you need to add the link flag "/export:mexFunction"
to your CMakeLists.txt
file. Example below:
PROJECT(example)
FIND_PACKAGE(Matlab REQUIRED)
INCLUDE_DIRECTORIES(${MATLAB_INCLUDE_DIR})
ADD_LIBRARY(example MODULE example.cpp)
ADD_DEFINITIONS(-DMATLAB_MEX_FILE)
# Needed for entry point.
SET_TARGET_PROPERTIES(example
PROPERTIES
LINK_FLAGS "/export:mexFunction"
)
# Change the dll extension to a mex extension.
set_target_properties(example PROPERTIES SUFFIX ".mexw64")
TARGET_LINK_LIBRARIES(example ${MATLAB_LIBRARIES})
注意 FIND_PACKAGE(Matlab的)
似乎并没有工作那么好,所以这可能是一些人的问题。我必须得到解决它通过硬编码在MATLAB路径进入的CMakeLists.txt(在本例中未示出)。
Note that the FIND_PACKAGE(Matlab)
doesn't seem to work all that well, so that may be a problem for some people. I had to get around it by hard-coding the MATLAB paths into CMakeLists.txt (not shown in this example).
这篇关于如何使用CMake和Visual Studio 2010中(64位),以建立一个MATLAB R2011a(64位)MEX文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!