Not able to integrate Matlab and VC++
Show older comments
Hi, I am trying to integrate Matlab and VC++, but no success so far. I am using MS Visual Studio .NET 2010 Professional; Matlab 2011b (fully licensed). My objective is to create a dll from matlab m file and then run it from VC++ program.
I am getting strange errors each time. These are my observations/ difficulties:
1. I could configure mex -setup and it detected VC++ compiler automatically. After accepting it, I did not set anything inside VC++ IDE.
2. I wrote functions in matlab and then try to make 'dll' from them, using mcc. But I could not execute mcc from matlab command window. However, mcc can be run from MS-Dos command prompt, But that is not working, though it is producing a dll file.
Is there any book (apart from mathworks site) clearly explaining the integration process (using mex files, s functions or dll etc) step-by-step with screen shots?
Is there any complete example (some sites have some examples on old versions of matlab and vc++, but they are not working either) that we can download and try?
Any method (other than dll) is ok, once it works.
Thanks in advance and please help me, David
Answers (1)
Kaustubha Govind
on 16 Nov 2011
0 votes
You are confused between two completely different Mathworks technologies:
- MEX-functions are used to call native code (C, C++, FORTRAN, etc.) from MATLAB. S-functions are a subset of MEX-functions that can be called from Simulink. Also, MEX-functions are basically DLLs under the hood, but with a platform specific extension (.mexw32, .mexw64, etc) and a required entry function called "mexFunction". The function "mex -setup" is used to setup the compiler used by the "mex" command which compiles C/C++ code into MEX binaries.
- The MATLAB Compiler product is used to compile MATLAB code into executables or libraries that can be deployed to a computer that does not have MATLAB installed. It requires additional MATLAB runtime libraries (called the MATLAB Compiler Runtime or MCR) to be packaged along with the deployed binary. This is where the "mcc" and "mbuild" commands belong.
To choose a compiler for running "mcc", you need to run "mbuild -setup" (not "mex -setup"). If you are unable to run the mcc command even after running "mbuild -setup", please post back with the exact error message that you see.
Also, FYI, there is another product called MATLAB Coder which lets you generate standalone C code from MATLAB code, but it only supports a limited subset of MATLAB functions.
1 Comment
david bathu
on 16 Nov 2011
Categories
Find more on MATLAB Coder in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!