I use "mbuild -setup" to choose the compiler. I work with different compilers to build standalone MATLAB applications. I am forced to run "mbuild -setup" every time to ensure that I am using the right compiler. I would like to know if there is any command that I could use to find out the compiler that is currently chosen.
MATLAB: How to know what compiler has been chosen previously using the “mbuild -setup” function
-setupcompilerMATLAB Compilerr14sp2
Related Solutions
The ability to add custom icons natively in a compiled application is available in the deploytool with release R2013b.
This is not possible in releases R2010b - R2013a.
If you are using MATLAB compiler 4.13 (R2010a) or before see below for any workarounds:
There are two ways to include a custom icon in a compiled application. One way is to modify the icon after the EXE has been generated using 3rd party software. The other way is to include the icon at compile time using a resource file. Each of these is explained further below.
1. In order to associate an icon with an application after the EXE has been created, you will need to use a 3rd party tool to modify the icon. There are many applications available for this purpose. A good place to start is by searching the "Downloads" area of some popular sites like https://www.pcworld.com/ and https://www.cnet.com/ .
2. If you wish to include the icon at compile time, you will need to make sure that your compiler supports this. The general process is to create a resource file which points to the icon, compile it with a resource compiler, and then include the compiled resource file when compiling the application.
Steps for MSVC Compiler:
1. Create a new Win32 Console Application
2. Right-click on "Resource Files" then select "Add->New Item"
3. In the new window, under "Visual C++", select "Resource"
4. Then in the "Visual Studio installed templates" section, select "Resource File (.rc)"
5. Specify a name for the resource file and click on "Add"
6. Right-click on "Resource Files" again and choose "Add Resource"
7. Select "Icon" and click "New"
8. Create the icon
9. Build the solution (F7)
10. Copy the generated .res file to the folder with the MATLAB code
11. Compile the MATLAB code:
mcc -m myfile.m -M icon.res
where icon.res is the compiled resource file. You can use the "-M" flag to specify compile-time options to your specific compiler. Type
doc mcc
for more information about this flag. These steps may vary depending on which version of Microsoft Visual Studio you are using. If you are not using a Microsoft compiler, you may want to see if your 3rd party compiler supports icon files.
Steps for LCC Compiler:
1. Let the icon file be named 'ship.ico'. If you have an image file (*.JPEG, *.TIFF, *.GIF, *.PNG...), you will need to use a 3rd party tool (you can search online for an image converter) to convert your image to a .ICO icon file.
2. Create a new text file and write "ConApp ICON ship.ico" in it. Rename it as "example.rc" and save it in your current directory.
3. Compile "example.rc" and "ship.ico" files using the following command at MATLAB prompt:
system(['"' matlabroot '\sys\lcc\bin\lrc" /i "' pwd '\example.rc"']);
After this step you will have a resource file "example.res" created in your working directory.
4. Compile the MATLAB files and the resource file together using the -M option as before:
mcc -m file1.m -M example.res
where file1.m can be any MATLAB File you want to deploy. This will create a "file1.exe" in your working directory with the same icon as "ship.ico".
If you are using MATLAB compiler 4.14 (R2010b) then see below:
Steps for MSVC Compiler:
Here instead of creating a '.exe' file, you will need to create a C shared library and write wrapper driver code that calls the main function of the application. More information about this can be found in the link below.
http://www.mathworks.com/help/releases/R2010a/toolbox/compiler/f13-1001757.html
A custom icon can then be associated with the EXE that is created when the driver code is compiled. For the sample driver code we are using FIGURETEST as the MATLAB function compiled into LIBFIGURE.DLL. Please follow the steps below once your DLL is created:
1. Create the C shared library using the link above.
2. Create a new Win32 Console Application named "test".
3. Right-click on "Resource Files" then select "Add->New Item"
4. In the new window, under "Visual C++", select "Resource"
5. Then in the "Visual Studio installed templates" section, select "Resource File (.rc)"
6. Specify a name for the resource file and click on "Add"
7. Right-click on "Resource Files" again and choose "Add Resource"
8. Select "Icon" and click "New"
9. Create the icon
10. Build the solution (F7)
11. Write your driver code in test.cpp and compile the VC++ console application by correctly providing the path to your library. Sample driver code is as follows.
// test.cpp : Defines the entry point for the console application.// libfigure is the Shared Library// Figuretest() is the main function in the library which corresponds to the // figuretest() function in the .m file which was compiled using mcc#include "stdafx.h"#include <libfigure.h>int _tmain(int argc, _TCHAR* argv[]){// Have to find out the pathsif( !mclInitializeApplication(NULL,0) ) { fprintf(stderr, "Could not initialize the application.\n"); return -1; }// Initialize the libraryif (!libfigureInitialize()){ fprintf(stderr,"Could not initialize the library.\n"); return -2; }else{//Call the figure librarymlfFiguretest();mclWaitForFiguresToDie(NULL);printf("Success");// TerminatelibfigureTerminate();mclTerminateApplication();}return 0;}
Steps for LCC Compiler:
There are no workarounds other than using third party products to insert the icon after compiling the application.
Microsoft Visual Studio 2015/2017 Professional does not install any C/C++ compiler by default. You need to select appropriate components specifically in the installation setting.
VS2015
VS2017
If you have already selected the C/C++ compilers during installation properly, confirm C program building is successful on Visual Studio.
If some trouble remains after that, please run the following commands and send us the full output message which this produces.
mex -setup -vmbuild -setup -v
Related Question
- Do I receive unresolved symbol errors when trying to compile the MATLAB function using graphics
- Does MATLAB hang or generate an error when I try to run mex -setup or mbuild -setup
- Matlab Compiler
- Am I getting the build error “Cannot determine the location of the VS Common Tools folder”
- Does MATLAB Coder locate the wrong toolchain when trying to build code for a specific hardware on the Linux machine (MATLAB R2017b)
- How to set up Microsoft Visual Studio 2008 Express Edition for use with MATLAB 7.7 (R2008b) on 64-bit Windows
- How to compile the .m file and use it in VC++
Best Answer