I would like to use my IDE (Visual Studio .Net 2003, etc.) to compile a MATLAB Engine application.
MATLAB: How to configure the IDE to compile MATLAB Engine applications
20036.0borlandcompileengineidelinkMATLABmsvcnetvs
Related Solutions
The "-v" flag for MCC, MBUILD, and MEX causes these commands to be more verbose, and display more information about their progress --- for example, which C/C++/Fortran/Java compiler is being used, what options are being passed to that compiler, and what temporary files are being used.
For more information on which items are reported by which functions, see the relevant documentation:
doc mccdoc mbuilddoc mex
In this example, we will use MCC -v, but the following information can be applied to any of the other "-v" commands. This example uses the MATLAB Compiler 2.1 (R12); other versions will report slightly different information.
mcc -v -m hello.m
The first section of output, shown below, is only seen in MCC (not MEX or MBUILD). This shows exactly what MATLAB files the MATLAB Compiler translated and their corresponding C or C++ files:
Compiler version: 2.1 Parsing file "D:\Applications\matlabr12\extern\examples\compiler\hello.m" (Referenced from: "Compiler Command Line"). Generating file "hello.h". Generating file "hello.c". Generating file "hello_main.c".
The next output shows the exact command that MCC is executing to call MBUILD. If we had used "-x" instead of "-m" in our command, MCC would call MEX here (instead of MBUILD).
Executing command: mbuild -O -v -output 'hello' 'hello.c' 'hello_main.c' -link exe.
The following is exactly what you would see if you ran the above MBUILD command. The first two lines of output here are especially important:
-> Default options filename found in C:\WINNT\Profiles\jfouche\Application Data\MathWorks\MATLAB\R12 ---------------------------------------------------------------- -> Options file = C:\WINNT\Profiles\jfouche\Application Data\MathWorks\MATLAB\R12\compopts.bat
These lines tell us the name and location of the options file that is being used to perform this compilation. In general it is not necessary to edit the options file, but if you needed to change any of the following settings, you could.
The following settings correspond exactly to what is in the options file listed above:
-> COMPILER = cl -> Compiler flags: COMPFLAGS = -c -Zp8 -G5 -W3 -nologo OPTIMFLAGS = -O2 -DNDEBUG DEBUGFLAGS = -Zi -Fd"hello.pdb" arguments = Name switch = /Fo -> Pre-linking commands = -> LINKER = link -> Link directives: LINKFLAGS = kernel32.lib user32.lib gdi32.lib /LIBPATH:"D:\Applications\matlabr12\extern\lib\win32\microsoft\msvc60" libmmfile.lib libmatlb.lib /nologo libmx.lib libmat.lib sgl.lib libmwsglm.lib Name directive = "/out:hello.exe" File link directive = Lib. link directive = Rsp file indicator = @ ----------------------------------------------------------------
Finally, the next few lines are the exact command-line statements passed into your C or C++ compiler. If you want to emulate the behavior of any of these scripts with an unsupported compiler, you can look at these lines and determine exactly what must be done in order to compile.
--> "cl -c -Zp8 -G5 -W3 -nologo /Fohello.obj -ID:\Applications\matlabr12\extern\include -ID:\Applications\matlabr12\simulink\include -O2 -DNDEBUG hello.c" hello.c --> "cl -c -Zp8 -G5 -W3 -nologo /Fohello_main.obj -ID:\Applications\matlabr12\extern\include -ID:\Applications\matlabr12\simulink\include -O2 -DNDEBUG hello_main.c" hello_main.c Contents of 5496_tmp.rsp: hello.obj hello_main.obj --> "link "/out:hello.exe" kernel32.lib user32.lib gdi32.lib /LIBPATH:"D:\Applications\matlabr12\extern\lib\win32\microsoft\msvc60" libmmfile.lib libmatlb.lib /nologo libmx.lib libmat.lib sgl.lib libmwsglm.lib @5496_tmp.rsp " --> "if exist _lib5496.def del _lib5496.def"
This error occurs when you do not link the required static library, libeng.lib which is located in $MATLAB/extern/lib/win32/microsoft. (where $MATLAB is the MATLAB root directory on your machine, as returned by typing
matlabroot
at the MATLAB command prompt.)
In order to link the required static library, perform the following steps: (these steps may differ by Microsoft Visual Studio version)
1. Select the project in the tree and then select Project->Properties menu item to open the 'Property pages' window.
2. Here select the 'Linker' node that is under the 'Configuration Properties' node. Add the $MATLAB/extern/lib/win32/microsoft directory to the 'Additional Library Directories' field.
3. Select the 'Input' node under the 'Linker' node. Add the libeng.lib file in the 'Additional Dependencies' field.
4. Build the project.
Other modifications to your settings may also be required, for general instructions on configuring Microsoft Visual Studio, please see the related solution below.
Best Answer