After generating MATLAB DLL, how do you implement in C++?

2 次查看(过去 30 天)
I'm trying to run a matlab program within my main c++ code. The below article is where I've been trying to run the example provided in Visual Studio 2015, by running mcc and build commands on the provided files (sierpinski.m, main_for_lib.c, main_for_lib.h, and triangle.c). I created a new project in Visual Studio 2015 and added all the header files to the header folder and all the rest of the files into the source files folder. I'm unable to build and run the program from "triangle.c" file, as the "mclmcrrt.h" file cannot be found. I looked back to my windows folder to see if one was ever generated and that answer is no, there wasn't one generated.
Here are my main questions on this issue:
  • by following this example, what is the mclmcrrt.h file and how would I access it?
  • how should all my files be added to my c++ project in visual studio, do I need to do some linking/include dependencies?
  • What is the main way in c++ to use a matlab dll and call the program in your code?
https://www.mathworks.com/help/compiler_sdk/cxx/matlab-compiler-generated-interface-functions.html

回答(1 个)

Varun Gunda
Varun Gunda 2017-4-3
If you are using the MCR to utilize the DLLs, please add the directory:
[MCR root]\extern
to your Visual Studio project path. [MCR root] is the MCR installation path on the system. For example: 'C:\Program Files\MATLAB\MATLAB Compiler Runtime\v716\extern'.
If you are using a MATLAB installation to utilize the DLLs, please add the directory:
[matlabroot]\extern
to your Visual Studio project path. [matlabroot] is the MATLAB installation directory on your system. For example: 'C:\Program Files\MATLAB\R2011b\extern'.
You can find [matlabroot] by typing the following command into the command window.
matlabroot
  1 个评论
Juliana Tobias
Juliana Tobias 2017-4-3
Hi Varun,
I've added the MCR root in Visual Studio to my project as an "Include Directory", is that the correct type of directory?
Also, which of the files produced from the mcc do I include in my project and where? For example, do I only include the dll under source files or do I need the dll, the .lib, and the .h files?
Thanks, Julie

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 C Shared Library Integration 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by