How do I create a stand-alone executable in the Microsoft Visual C/C++ 5.0 IDE from the project files in $MATLAB/ex​tern/examp​les/cppmat​h/msvc?

2 views (last 30 days)
I would like to create a stand-alone C or C++ executable in the Microsoft Visual C/C++ 5.0 IDE from the project files in $MATLAB/extern/examples/cmath/msvc or $MATLAB/extern/examples/cppmath/msvc.
Were the project files in $MATLAB/extern/examples/cmath or cppmath updated for use with the C++ Math Library 1.2?

Accepted Answer

MathWorks Support Team
MathWorks Support Team on 27 Jun 2009
We are unable to offer complete technical support on the details of using any specific one of the large number of IDE environments our customers use. If you need detailed assistance with the particular settings needed to get your IDE environment to generate code that successfully compiles and runs with our products, we suggest you contact the manufacturer of your IDE to get either information or expert technical assistance in using it.
See the Related Solution for a working project file for MSVC 6.0 on Windows NT.
If you do not have MSVC 6.0, you will need to follow these steps to create a stand-alone C or C++ executable with the Microsoft Visual C/C++ 5.0 IDE and C/C++ Math Libraries, and the C/C++ Graphics Library:
1. Start up the Microsoft Visual C/C++ 5.0 IDE
2. Go to FILE and NEW. Click on Projects Tab. Select Win32 Console Application. In the Project Name field type: ex1. Create new workspace should be filled in. In the Platforms field, Win32 should also be checked. Click OK.
3. Go to the MAIN menu and click on Project, Add to Project, New. Click on Projects Tab. Select Win32 Static Library. In the Project Name field type in libmx. Add to current workspace should be filled in. Dependency of should be checked. In the listbox select ex1. In the Platforms field, Win32 should be checked. Click OK.
4. Highlight Workspace 'ex1': 2 project(s) and then right click. Select Add new project to workspace. Click on Projects Tab. Select Win32 Static Library. In the Project Name field type in libmcc. Add to current workspace should be filled in. Dependency of should be checked. In the listbox select ex1. In the Platforms field Win32 should be checked. Click OK.
5. Do step 4 for libmmfile and libmatlb. If you are building a project which requires the Graphics Library, you should also do this for sgl.
6. Highlight ex1 files. Right click and select Set as Active Project.
7. Highlight ex1 files. Right click and select New Folder. In the Name of the new folder field type in Sources. Click OK.
8. Do step 7 for libmatlb files, libmx files, libmcc files, and libmmfile files. Replace ex1 with the appropriate names. If you are building a project which requires the Graphics Library, you should also do this for the sgl files.
NOTE: You do not need libmcc files for MATLAB R12 or higher
9. Double click on ex1 files. Highlight Sources and then right click. Select Add files to folder. Go to $MATLAB/extern/examples/cppmath and select ex1.cpp. $MATLAB represents the root directory where MATLAB is installed.
10. Double click on libmx files. Highlight Sources and then right click. Select Add files to folder. Go to $MATLAB/extern/include and select libmx.def.
11. Do step 10 for libmatlb files, libmcc files, and libmmfile files. Replace libmx with the appropriate names. If you are building a project which requires the Graphics Library, you should also do this for the sgl files.
12. Double click on libmatlb files and double click on Sources. Right click on libmatlb.def and select Settings. This brings up a Project Settings window. Click on Custom Build Tab. In the Build Command(s) field enter:
lib /def:"c:\matlab\extern\include\libmatlb.def" /machine:ix86 /OUT:libmatlb.lib
c:\matlab represents the root directory where MATLAB is installed on your system.
In the Output file(s) field type: libmatlb.lib.
Click OK.
13. Do step 12 for libmx files, libmmfile files, and libmcc files. Replace libmatlb with the appropriate names. If you are building a project which requires the Graphics Library, you should also do this for the sgl files.
14. Highlight ex1 files and right click. Select Settings. Click on the C/C++ Tab. In the Category listbox select Code Generation. In the Use Runtime library listbox select Multithreaded DLL. Change the Category listbox to Preprocessor. Add to the Preprocessor definitions MSVC, MSWIND, IBMPC so:
WIN32,_DEBUG,_CONSOLE,_MBCS
changes to:
WIN32,_DEBUG,_CONSOLE,_MBCS,MSVC,MSWIND,IBMPC
Add to the Additional include directories field:
c:\matlab\extern\include\cpp;c:\matlab\extern\include;
c:\matlab\extern\include\cpp is only necessary if you are using the C++ Math Library.
Click on the Link Tab. Select in the Category listbox General. If you are creating C++ executables you will need to add libmatpm.lib to the Object/Library modules field. If you are creating C executables you do not need to add libmatpm. Therefore, for C++ applications, the Object/Library modules field would change from:
kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib
to:
c:\matlab\extern\lib\libmatpm.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib
Click OK.
15. Go to Build and Rebuild All.
16. Go to Build and Execute ex1.exe.

More Answers (0)

Community Treasure Hunt

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

Start Hunting!