Matlab generates dll file notes

Non-teaching, failure case.

1 Download MinGW64 C/C++ Compiler

Download link: https://sourceforge.net/projects/mingw-w64/files/
Baidu cloud download link: Link: https://pan.baidu.com/s/11erb1P3KLAFD1UxCJIZ8Tw?pwd=jvh6
Extraction code: jvh6
1. Click Files:
insert image description here

2. Pull down until the picture below, click x86_64_win32_sjlj. (The MATLAB I use is R2019a, and it can be installed normally with version 6.4.0.)
insert image description here
3. The folder to be unzipped after downloading needs to ensure that there are no spaces! Parent folders must not contain spaces either! Program FilesWill not work.
insert image description here
4. Add system environment variables:
(1) Right-click My Computer -> Properties.
insert image description here

(2) Click Advanced System Settings.
insert image description here

(3) Click: Advanced, Environment Variables.
insert image description here

(4) Click System Variables, Create New:
insert image description here
Just confirm it all the time.

2 Matlab installation and configuration

Enter in the matlab command line:

setenv('MW_MINGW64_LOC','C:\mingw64')
mex -setup
mex -setup c++

insert image description here

3 compile test

Write a .m function, only the function (function) can compile and generate dll/lib/c/h files.
insert image description here
test_func.m

function [add,minus] = test_func(num1,num2)
    add = num1 + num2;
    minus = num1 + num2;
end

After saving, in this folder, enter the command line:

mcc -W cpplib:test_func -T link:lib test_func.m -C

Explanation:
-W is to control the packaging format after compilation;
-T means the target, link:lib means the target to be connected to a library file, and the name of the target is the name of the .m function.
Other specific meanings can be viewed through the mcc –help command, pay attention to the upper and lower case of the parameters.
insert image description here
Enter the folder, you can see that the dll/lib/c/h files have been compiled and generated.
insert image description here

4 Another compilation method

Command line input:

mbuild -setup
mex -setup C++ -client MBUILD
deploytool

Wait for the popup to click Library Compiler.
insert image description here
According to the figure below, click C++ Shared Library, click the plus sign +, you can see the four files to be generated at the bottom, click Package, click 确定.
insert image description here

After the operation is complete, a .prj file and a folder are generated, inside the folder:

文件路径:
test_func.m
test_func.prj
test_func
			- for_redistribution
									- MyAppInstaller_web.exe
			- for_redistribution_files_only
									- v2
									- test_func.dll						*****
									- test_func.h						*****
									- test_func.lib						*****
									- GettingStarted.html
			......

The files marked with an asterisk *****are required.

5 This dll can't be used! !

Copy test_func.h, test_func.dll, test_func.lib to the Qt project directory, add various matlab file paths under the pro file, and then use the functions in the .h file under the main.cpp file, but the compilation has not been pass! ! ! Either the file cannot be found, or the permissions are blocked.


Reference link:
https://www.cnblogs.com/zzzsj/p/14630559.html

Guess you like

Origin blog.csdn.net/qq_45362336/article/details/130684967