This example passes string variables into and out of a C++ shared library built with MATLAB Compiler 4.5 (R2006b). It is based on the C++ shared library example in the documentation
web([docroot,'/toolbox/compiler/f2-995712.html'])
1. Building the shared library
Download the following attached files your work directory, using the links at the bottom of this page:
Note: revdriver.cpp contains the driver application's main function.
2. Compiling the library
First, choose your C++ compiler:
To create the shared library, execute the following command:
mcc -B cpplib:librevp revstr.m -v
The arguments to the MCC command are explained in the C++ shared library example.
3. Compiling the driver application
To compile the driver code (revdriver.c) using the selected C/C++ compiler, execute the following platform-specific MBUILD command
mbuild revdriver.cpp librevp.lib (Windows)
mbuild revdriver.cpp -L. -lrevp -I. (UNIX)
This generates a driver application, revdriver.exe, on Windows, and revdriver, on UNIX.
4. Running the driver application
To execute the standalone application, add the directory containing the shared library to your dynamic library path. Also update the dynamic library path for your platform by following the instructions in the section 'Developing and Testing Components on a Development Machine' of the 'Getting Started' chapter.
Execute the driver application from the system command prompt by typing the application name:
The results are displayed as:
The value of the original string is:
This is a string...
The value of the modified string is:
...
Viewed as a C++ string, the value is:
...
Best Answer