Matlab导出C、C++、动态库
一、生成动态库
1.编写matlab函数Test_Dll.m
function [res] = Test_Dll(a, b)
res = a+b;
end
2.打开app->MATLAB Coder
3.选择matlab函数文件
4.设置入参类型,这里都设置成double(1x1)
5.CHECK FOR ISSUES,没报错直接过
6.GENERATE生成
Build type设置为动态库Dynamic Library,点击Generate;
7.生成成功
8.在Test_Dll文件夹里
所有的c、h文件,和Test_Dll.lib、Test_Dll.dll文件就是需要的
9.在Qt工程中使用
pro中:
INCLUDEPATH += $$PWD/third_party/DLL
LIBS += -L$$PWD/third_party/DLL -lTestAdd
main中:
#include "Test_CPP.h" int main(int argc, char *argv[]) { QCoreApplication a(argc, argv); qDebug()<<Test_CPP(1,2); return a.exec(); }
二、生成C代码
1.编写matlab函数Test_C.m
function [res] = Test_C(a, b)
res = a+b;
end
2.打开app->MATLAB Coder
3.选择matlab函数文件
4.设置入参类型,这里都设置成double(1x1)
5.CHECK FOR ISSUES,没报错直接过
6.GENERATE生成
Build type设置为动态库Source Code,语言选择C,点击Generate;
7.生成成功
8.在Test_C文件夹里
所有的c、h文件就是需要的
9.在Qt工程中使用
右键工程添加所有源码;
pro中:
INCLUDEPATH += $$PWD/third_party/C
main中:
#include "Test_CPP.h" int main(int argc, char *argv[]) { QCoreApplication a(argc, argv); qDebug()<<Test_CPP(1,2); return a.exec(); }
三、生成C++代码
1.编写matlab函数Test_CPP.m
function [res] = Test_CPP(a, b)
res = a+b;
end
2.打开app->MATLAB Coder
3.选择matlab函数文件
4.设置入参类型,这里都设置成double(1x1)
5.CHECK FOR ISSUES,没报错直接过
6.GENERATE生成
Build type设置为动态库Source Code,语言选择C++,点击Generate;
7.生成成功
8.在Test_CPP文件夹里
所有的c++、h文件就是需要的
9.在Qt工程中使用
右键工程添加所有源码;
pro中:
INCLUDEPATH += $$PWD/third_party/CPP
main中:
#include "Test_CPP.h" int main(int argc, char *argv[]) { QCoreApplication a(argc, argv); qDebug()<<Test_CPP(1,2); return a.exec(); }
说明:
1.在GENERATE的时候,点击More Setting可以设置更多内容
2.在More Setting-Hardware中,可以设置编译的工具链,默认是VC++
3.如果设置复数类型,设置入参类型的时候勾选上Complex number
长风破浪会有时,直挂云帆济沧海!
可通过下方链接找到博主
https://www.cnblogs.com/judes/p/10875138.html