C++ 将问题与cmake和cygwin联系起来

C++ 将问题与cmake和cygwin联系起来,c++,compilation,cygwin,cmake,mex,C++,Compilation,Cygwin,Cmake,Mex,以下是设置: 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 P

以下是设置:

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"

一切似乎都是正确的?

${matlab_LIBRARIES}
中使用matlab libs的顺序。我已经这样做了,但没有区别。我从
FindMatlab.cmake
宏获得了命令。这个问题与visual studio编译器的
/export:mexFunction
链接器标志有关吗?