Matlab2015b使用MinGW64(TDM-GCC)编译mex

更新时间:2024-04-13 10:41:01 阅读量: 综合文库 文档下载

说明:文章内容仅供预览,部分内容可能不全。下载后的文档,内容与下面显示的完全一致。下载之前请确认下面内容是否您想要的,是否完整无缺。

Install MinGW-w64 Compiler You can use the MinGW-w64 version 4.9.2 compiler from TDM-GCC to build MEX files and standalone MATLAB engine and MAT-file applications.

?

Installing Compiler from Add-Ons Menu

To install the MinGW compiler, open the installer from MATLAB Add-Ons menu. On the Home tab, in the Environment section, click the Add-Ons icon. Under Refine by Type, select Features, or search for MinGW. Follow the prompts to add the compiler.

Note: To install the MATLAB-supported version of MinGW-w64, you must clear the check box highlighted in the following figure.

MinGW Installation Folder Cannot Contain Space

Do not install MinGW in a location with spaces in the path name. For example, do not use:

C:\\Program Files\\TDM-GCC-64

Instead, use:

C:\\TDM-GCC-64

Troubleshooting and Limitations Compiling C/C++ MEX Files with MinGW-w64

Do Not Link to Library Files Compiled with Non-MinGW Compilers

If you use the MinGW compiler to build a MEX file that links to a library compiled with a non-MinGW compiler, such as Microsoft Visual Studio, the file will not run in MATLAB. Library (.lib) files

?

?

?

generated by different compilers are not compatible with each other. You can generate a new library file using the dlltool utility from MinGW.

MinGW Compiler Not Setup for Use with MEX

If you installed the MinGW compiler but MATLAB does not recognize it, the compiler might not be the supported version.

To install the MATLAB-supported version of MinGW-w64, you must clear the Check for updated files on the TDM-GCC server check box. This check box appears during TDM-GCC Setup when you are asked to Choose which action you want the setup wizard to perform. For information about installing MinGW, see Installing Compiler from Add-Ons Menu.

MinGW Installation Folder Cannot Contain Space

Do not install MinGW in a location with spaces in the path name. For example, do not use:

C:\\Program Files\\TDM-GCC-64

Instead, use:

C:\\TDM-GCC-64

MEX Command Does not Choose MinGW

If you only have the MinGW compiler installed on your system, the mex command automatically chooses MinGW for both C and C++ MEX files. If you have multiple C or C++ compilers, use mex

-setup to choose MinGW for both C and, if required, C++ MEX files.

mex-setup mex-setupcpp

If you only type mex -setup choosing MinGW, when you compile a C++ file, mex might choose a

different compiler.

Manually Configure MinGW for MATLAB

MATLAB detects the MinGW compiler by reading an environment variable, MW_MINGW64_LOC. When you install MinGW from the MATLAB Add-Ons menu, MATLAB sets this variable.

If necessary, you can set this variable globally, if you have Windows administrative privileges, using the

?

Windows Control Panel. Alternatively, set the variable every time you open MATLAB.

Note: Verify you have installed MinGW-w64 version 4.9.2 before setting the environment variable.

Set variable using Windows Control Panel To set the environment variable on Windows 7: 1. Make sure you have administrative privileges. 2. Select Computer from the Start menu.

3. Choose System properties from the context menu. 4. Click Advanced system settings > Advanced tab. 5. Click Environment Variables. 6. Under System variables, select New.

7. In the New System Variable dialog box, type MW_MINGW64_LOC in the Variable

name field.

8. In the Variable value field, type the location of the MinGW-w64 compiler installation, for

example, C:\\TDM-GCC-64.

9. Click Ok to close the dialog boxes, then close the Control Panel dialog box. Set variable for MATLAB session

To set the environment variable in MATLAB, type:

setenv('MW_MINGW64_LOC',folder)

where folder is the installation directory, for example, 'C:\\TDM-GCC-64'. You must set the

variable every time you run MATLAB.

本文来源:https://www.bwwdw.com/article/hhsp.html

Top