0

这是设置:

set(CMAKE_FIND_LIBRARY_SUFFIXES .lib .dll.a .a)
set(MATLAB_MEXFILE_EXT mexw64)
find_file(MATLAB_ROOT matlab $ENV{ProgramW6432})
set(MATLAB_LIBRARIES_DIR ${MATLAB_ROOT}/extern/lib/win64/microsoft)

find_path(MATLAB_INCLUDE_DIR
  NAMES mex.h
  PATHS ${MATLAB_ROOT}
  PATH_SUFFIXES extern/include
  NO_DEFAULT_PATH
)

include_directories(${MATLAB_INCLUDE_DIR})

find_library(MATLAB_MEX_LIB mex ${MATLAB_LIBRARIES_DIR} NO_DEFAULT_PATH)
find_library(MATLAB_MX_LIB mx PATHS ${MATLAB_LIBRARIES_DIR} NO_DEFAULT_PATH)
find_library(MATLAB_MAT_LIB mat PATHS ${MATLAB_LIBRARIES_DIR} NO_DEFAULT_PATH)
set(MATLAB_LIBRARIES ${MATLAB_MEX_LIB} ${MATLAB_MX_LIB} ${MATLAB_MAT_LIB})

add_library(mytest SHARED mytest.cpp)
target_link_libraries(mytest ${MATLAB_LIBRARIES})

但是当我运行时,make我会收到以下类型的错误:

undefined reference to `_mexErrMsgIdAndTxt'

显然是链接问题。但是为什么会发生呢?这是make命令的输出:

/usr/bin/c++.exe -Dmytest_EXPORTS -I"/cygdrive/c/Program Files/matlab/extern/include"    -o CMakeFiles/mytest.dir/mytest.cpp.o -c /home/hous/workspace/mytest.cpp

/usr/bin/c++.exe -shared -Wl,--enable-auto-import -o mytest.mexw64 -Wl,--out-implib,libmytest.dll.a -Wl,--major-image-version,0,--minor-image-version,0 CMakeFiles/mytest.dir/mytest.cpp.o "/cygdrive/c/Program Files/matlab/extern/lib/win64/microsoft/libmex.lib" "/cygdrive/c/Program Files/matlab/extern/lib/win64/microsoft/libmex.lib" "/cygdrive/c/Program Files/matlab/extern/lib/win64/microsoft/libmx.lib" "/cygdrive/c/Program Files/matlab/extern/lib/win64/microsoft/libmat.lib"

一切似乎都是正确的?

4

0 回答 0