原创文档(matwav里的win32asm就是me,cc) VC直接调用matlab生成的dll文件 参考资料:Matlab 7 帮助文档 应用环境:Windows XP,Matlab 7.0.0,Visual C++ 6.0 ============================================================================== * Matlab里的设置及命令 * 1. 编写相关的函数文件(如myFFT.m, mySpectrum.m,直接调用matlab的fft,psd等) * 2. mcc -setup 配置编译器mcc,选择vc * 3 mbuild -setup 配置build,选择vc * 4. 利用matlab编译器mcc生成相应的库函数和头文件,以及CTF文件(必须的) * mcc -W lib:myDll -T link:lib myFFT.m,mytypectrum.m * 生成了.lib, .dll, .h, .ctf * * * VC里的设置 * 1. 拷贝4个文件到VC工作目录中 .dll, .lib, .h, .ctf * 2. Tools->Options->Directories->Inlucde files * 添加路径 C:/MATLAB/EXTERN/INCLUDE * 3. Tools->Options->Directories->Library files * 添加路径C:/MATLAB/EXTERN/LIB/WIN32/MICROSOFT/MSVC60 * 4. project->settings->Link->Project Options * 添加libmatrix.lib libmx.lib libmex.lib mclmcr.lib (libeng.lib 待定) * *注:libmatrix.lib 是程序员在Matlab基础上开发的库文件 * 5. 程序中首先初始化MCR mclInitializeApplication() * 6. 初始化共享库实例fftDllInitialize(); 这里fftDll是生成库的名字 * 7. 由于Matlab所生成的库文件是以mxArray为基本计算单位,因此需要用mxArray定义入口指针变量 * 8. 调用完成后,依次mxDestroyArray,fftDllTerminate(注:fftDll为库文件名),mclTerminateApplication * 注:由于Matlab接口中较多的使用了指针,因此,一定要注意释放指针 * * Windows环境下移植库文件(脱离matlab环境) * 1. 拷贝C:/MATLAB/toolbox/compiler/deploy/win32/MCRInstaller.exe到目标机器 * 2. 安装MCR (MATLAB Component Runtime) * 3. 把MCR的安装路径加入到windows的环境变量的Path路径中
/runtime/win32 * 4. 拷贝应用组件(.dll, .exe, .ctf文件)到应用目录中运行 ================================================================================ 注:用本方法编写出的程序运行较慢,不适于实时性计算 术语: MATLAB Component Runtime (MCR) interface functions (wrappers) Component Technology File (CTF) archive The initialize routine now returns a status flag that can be used to test if the library was initialized properly. Component Object Model (COM) Advanced Encryption Standard (AES) 移植: Deploying Components to Other Machines To deploy your component to a target machine that does not have the same version of MATLAB installed as your development machine (or any version of MATLAB for that matter), you need to package the components and configure the target machines as follows. 1. Your component, i.e., the stand-alone executable or shared library The CTF archive that is created for your component (
.ctf) 2. MCRInstaller.exe(This file is located in the
/toolbox/compiler/deploy/win32 directory.) On the target machine, do the following: 1. Install the MCR by running the MCR Installer in a directory. For example, run MCRInstaller.exe in C:/MCR. 2. Copy the component and CTF archive to your application root directory, for example, C:/approot. 3. Add the following directory to your system path:
/runtime/win32 4. Test the component.
c与matlab混合编程之dll调用
最新推荐文章于 2023-08-16 23:36:57 发布