Can I use a dll library generated by MATLAB Coder in a separate cpp file using Microsoft Visual Studio Project?

1 次查看(过去 30 天)
I have used Matlab Coder to generate DLL-files of the "umbrella function" myFun.m, which is an entry function which calls another entry function, mySubFun.m.
Now I want to let a huge, external cpp-solution call the cpp-generated version of mySubFun() without using mySubFun.cpp, instead by using myFun.dll.
How do I approach this?

采纳的回答

MathWorks Support Team
I have created a simple example for your application.
1. In hello_world.m, we have
function y = hello_world %#codegen
y = mySubFun;
2. In mySubFun.m, we have
function y = mySubFun %#codegen
y = 'Hello World!';
% Copyright 2010 The MathWorks, Inc.
3. Create a coder project helloworldtest.prj, and add the two MATLAB files into the Entry-Point files, and build the dll.
4. Add the directory for the generated .dll into Windows System Path
5. Open Visual Studio, create an empty win32 Console Application project. Add main.cpp in the source files with the following code
#include "hello_world.h"
#include "mySubFun.h"
#include<stdio.h>
int main(){
char y[12];
mySubFun(y);
for(int i = 0; i < 12; i++)
printf("%c",y[i]);
printf("\n");
return 0;
}
6. In the property of the project. Add the directory of generated dll file to the 'Additional Include Directories' under C/C++ -> General and ‘Additional Library Dependencies' under Linker -> General. Add hello_world.lib in the field 'Additional Dependencies' under Linker -> Input.
Once you complete the above steps, the simple main file we created in step 5 would be able to compile and run correctly by calling the dll generated using MATLAB Coder.
Copyright 2010 The MathWorks, Inc.

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 MATLAB Coder 的更多信息

标签

尚未输入任何标签。

产品


版本

R2014a

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by