[MATLAB] C ++ and Matlab hybrid programming-previous

Source: Internet
Author: User
Tags visual studio 2010

Recently, the project used a lot of knowledge about digital signal processing. Because this part is not very familiar with programming, and MATLAB provides a wide range of digital signal processing toolboxes, MATLAB has become a good choice.

When trying to integrate the MATLAB program into C ++, I encountered many problems.

MATLAB 7.0 and later use MCR (MATLAB compiler runtime) and CTF (Component Technology file) technology. Previous compilers focused on compiling MATLAB programs into C/C ++ programs (like matcom4.5), but later focused on compiling them into MCR executable programs.

Put a short section here: the Matlab code is very simple, and the elements are much less than C ++. Therefore, it is completely feasible to translate the Matlab code into C ++ in principle, MATCOM adopts this policy and provides a MATCOM matrix calculation mathematical library. In C ++, math can be used. the algorithms in C are the same as those in MATCOM. Then we can see that the major problem with this development is that the MATLAB core code will be made public, so MATLAB acquired MATCOM and solved this problem through MCR technology. Note that after compilation, only the interface file is provided, instead of the C ++ code of the non-core algorithm. However, there are still many toolboxes that cannot be compiled using Matlab.

MCR is actually a dynamic link library provided by MATLAB. You can run the maltab program on a machine without Matlab installed. CTF packages the program to be released as a CFT file (this file is encrypted by code ). The compiled executable program or library file or COM component is linked to the east. The compiled Matlab code is automatically transferred to MCR for execution during execution (or called by the main program.

Use the MATLAB Compiler:

Run the mbuild-setup command in MATLAB and the following information is displayed:

>> mbuild -setupPlease choose your compiler for building standalone MATLAB applications:  Would you like mbuild to locate installed compilers [y]/n? y Select a compiler: [1] Lcc-win32 C 2.4.1 in C:\PROGRA~1\MATLAB\R2010b\sys\lcc [2] Microsoft Visual C++ 2010 in C:\Program Files\Microsoft Visual Studio 10.0 [3] Microsoft Visual C++ 2008 SP1 in C:\Program Files\Microsoft Visual Studio 9.0  [0] None  Compiler: 2 Please verify your choices:  Compiler: Microsoft Visual C++ 2010  Location: C:\Program Files\Microsoft Visual Studio 10.0  Are these correct [y]/n? y ****************************************************************************   Warning: Applications/components generated using Microsoft Visual C++                 2010 require that the Microsoft Visual Studio 2010 run-time                  libraries be available on the computer used for deployment.                  To redistribute your applications/components, be sure that the               deployment machine has these run-time libraries.                  ****************************************************************************  Trying to update options file: C:\Users\IDM\AppData\Roaming\MathWorks\MATLAB\R2010b\compopts.bat From template:              C:\PROGRA~1\MATLAB\R2010b\bin\win32\mbuildopts\msvc100compp.bat  Done . . . 

[1. In this way, the compiling environment is configured.

Then you can compile your header file. For example, my header file is plotdata. M.

mcc -W lib:plotdata plotdata.m -T link:lib

MCC is a dynamic link library compiled as a C interface. -W Lib is a dynamic link library that compiles plotdata. m into plotdata.

Another bundling command using csharedlib is equivalent:

mcc -B csharedlib:plotdata plotdata.m

After compilation, a pile of files will be generated in the directory of your M file:

Mccexcludedfiles. log records files that cannot be compiled by Matlab. However, it seems that the information in each line is the same ......

If you use Implicit Dynamic Links, you need to put plotdata. C, plotdata. H, plotdata. Lib, and plotdata. dll in your project.

If you want to explicitly load the dynamic link library, you only need plotdata. dll.

See the next article: C ++ and Matlab Mixed Programming-DLL

(Reprinted please indicate the author and Source: http://blog.csdn.net/xiaowei_cqu is not allowed for commercial use)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.