How to use CMake and Visual Studio 2010 (64 bit) to build a MATLAB R2011a (64 bit) mex file?

只谈情不闲聊 提交于 2019-12-06 15:57:15

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})

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).

Matlab mex files are dll`s not libs. Try making cmake (not an expert on that) create a dynamic librart، not static.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!