参考: https://ww2.mathworks.cn/help/compiler_sdk/gs/create-a-cc-matlab-data-application.html
https://ww2.mathworks.cn/help/compiler_sdk/cxx_mwArray_API_shared_library.html
https://ww2.mathworks.cn/support/search.html/answers/549564-how-do-i-build-a-driver-application-for-a-c-matlab-data-api-shared-library-using-microsoft-visual.html?fq[]=asset_type_name:answer&fq[]=category:compiler_sdk/cxx_MATLAB_Data_API_shared_library&page=1
https://ww2.mathworks.cn/help/compiler_sdk/cxx_MATLAB_Data_API_shared_library.html?s_tid=CRUX_lftnav
https://ww2.mathworks.cn/help/compiler_sdk/gs/create-a-cc-mwarray-application.html
环境: win10、matlab2020a、qtcreater5.12.10(mingw64)
1.mex -setup,return
no compile(提示没有编译器)
2.
3
4选择安装
5编写脚本myFunc.m
function [C]=myFunc(A,B)
C=A+B;
end
6
7输入libraryCompiler
8使用生成的 for_redistribution_files_only instructions(目录中的)myFunc.dll、myFunc.h、myFunc.lib
9在pro文件中添加
INCLUDEPATH += $$PWD/include
LIBS += -L$$PWD/include/ -lmyFunc
INCLUDEPATH += ../../matlab2020a/extern/include
INCLUDEPATH += ../../matlab2020a/extern/include/win64
# 用到的MATLAB 的.lib库文件
INCLUDEPATH += ../../matlab2020a/extern/lib/win64/mingw64
DEPENDPATH += ../../matlab2020a/extern/lib/win64/mingw64
LIBS+= -L../../matlab2020a/extern/lib/win64/mingw64 -llibmex
LIBS+= -L../../matlab2020a/extern/lib/win64/mingw64 -llibmx
LIBS+= -L../../matlab2020a/extern/lib/win64/mingw64 -llibmat
LIBS+= -L../../matlab2020a/extern/lib/win64/mingw64 -llibeng
LIBS+= -L../../matlab2020a/extern/lib/win64/mingw64 -lmclmcr
LIBS+= -L../../matlab2020a/extern/lib/win64/mingw64 -lmclmcrrt
10Cpp文件中
11编译 没有问题 运行提示
`../../matlab2020a\bin\win64\icudt64.dll':Shared library architecture i386 is not compatible with target architecturei386:x86-64.
SetThrowSegvLongjmpSEHFilter(): filterfunction ../../matlab2020aed
12运行myFuncInitialize 崩溃
13解决方法把mclInitializeApplication(NULL,0) 替换成
const char *args[] = {"-nojvm"};
const int count = sizeof(args) / sizeof(args[0]);
mclInitializeApplication(args, count);
注意最后需要 不需要用 matlab生成库后需要添加
mclTerminateApplication(); //不添加程序不能正常退出
xxTerminate();//xx位库的名称
本人电脑 编译matlab导出的mingw和msvc的c++动态库都可以。 但是本人matlab 不能导出 msvc编译器的c++动她库(可能是因为我的vs重新装过)
这里有一个大坑 就是这样调用了之后, 打开mysql 数据库失败