Frequently-asked questions (FAQ)
How do I fix the error
Attempt to execute SCRIPT vl_nnconv as a function?
Before the toolbox can be used, the MEX files must be compiled. Make sure to follow the installation instructions. If you have done so and the MEX files are still not recognized, check that the directory
matlab/toolbox/mex contains the missing files. If the files are there, there may be a problem with the way MEX files have been compiled.
Why files such as
vl_nnconv.m do not contain any code?
These functions are MEX files.
Do I need a specific C++ compiler version?
Officially, different MATLAB versions support only specific versions of each compiler (Xcode, GCC, and Visual Studio). If needed, it is usually possible to install an old compiler version alongside any newer version you may have.
Do I need a specific version of the CUDA devkit?
Officially, MathWorks supports a specific version of the CUDA devkit with each MATLAB version (see here). However, in practice we normally use the most recent version of CUDA (and cuDNN) available from NVIDIA without problems (see here). This will require using the
nvcc compilation method or to customize the mex configuration files.
Can I use MatConvNet with CuDNN?
Yes, and this is the recommended way of running MatConvNet on NVIDIA GPUs. However, you need to install cuDNN and link it to MatConvNet. See the installation instructions to know how.
How do I customize the
mex configuration files?
Stubborn compilation problems can usually be solved by tweaking the configuration of the
mex compiler. This is done by editing the mex configuration files. In order do so, start by creating a copy of the relevant files, apply your changes, and use the
MexCudaConfig options of
vl_compilenn to use them instead of the default ones.
There are two flavour of such files relevant to MatConvNet:
The mex configuration for C++ is automatically copied to the user's MATLAB preference directory by running
mex -setup. The preference directory can be discovered by using the
prefdir()command in MATLAB and the file has a name of the type
mex_C++_win64, or similar.
It is safe to edit this file, but it will be overwritten upon calling
mex -setup, so consider creating a copy instead and the use the
vl_compilennto use it.
The mex configuration for CUDA. This is not copied to the user's preference directory; its location can be found by using the MATLAB command
fullfile(toolboxdir('distcomp'), 'gpu', 'extern', 'src', 'mex', computer('arch'))and the file name will be of the type
nvcc_msvcpp2015.xml. Copy it to a custom directory (for example MatConvNet folder or the user's preference directory
prefdir()), edit it, and then use the
MexCudaConfigoption to instruct
vl_compilennto use it.
I am getting the error
No supported compiler or SDK was found. What can I do?
This occurs when MATLAB cannot identify a compatible compiler version. Usually, this is most likely to occur when compiling CUDA code using the
mex method, as both constraints imposed by MATLAB and the CUDA compiler NVCC are combined. There are three solutions:
Try to compile CUDA code using the
nvccmethod instead of the
mexmethod. This skips MATLAB and uses NVCC directly to compile CUDA code relaxing many constraints.
Install the exact compiler and CUDA requirements imposed by the specific MATLAB (note that each MATLAB MATLAB has an officially-supported CUDA version a corresponding compiler version). For macOS see also here.
mexconfiguration files to relax some constraints as explained above. Some of the issues that can be addressed by this method are further discussed in the other points of the FAQ.
I am getting the
error: 'constexpr' does not name a type when compiling MatConvNet. What can I do?
You are likely compiling MatConvNet CUDA code using the
mex method and an old MATLAB version. The
mex configuration file contained an odd bug for which both the options
-ansi would be specified. Either:
- Use the
nvccmethod to compile MatConvNet or
- Hack the mex CUDA configuration file as explained above and remove any occurrence of the string
Linux: Why do I get compilation error
error: unrecognized command line option "-std=c++11"?
Use a GCC that supports C++11; yours is likely too old (<4.6).
macOS: I have Xcode installed, but I still cannot compile MatConvNet. What can I do?
There are a few common sources of issues:
mex -setupfails because Xcode is not compatible with your MATLAB version. The solution is to install an old version of Xcode.
mex -setupcannot find a compatible SDK. A solution is suggested here.
macOS: How can I use an old version of Xcode?
MATLAB can be picky about the supported version of Xcode, and further restrictions may apply when using GPU code (see below). If
mex -setup complains that no suitable Xcode version can be found, the safest option is to download an old version of Xcode (from developer.apple.com, requires a free developer account) and install it in a location such as
You can then:
Start MATLAB form the command line after setting the
DEVELOPER_DIRenvironment variable, as in
export DEVELOPER_DIR=/Applications/Xcode7.3.1.app/Contents/Developer /Applications/MATLAB_R2016a.app/bin/matlabwhere paths need to be adjusted to your situation. The advantage of this method is that it does not require changing your default Xcode selection.
xcode-selectto activate the old version of Xcode globally and then
xcode-select --installto install the corresponding command line tools; for example:
sudo xcode-select --switch /Applications/Xcode7.3.1.app/Contents/Developer sudo xcode-select --install
mex -setup should be able to find and use the old compiler.
macOS: mex is complaining about missing SDKs. What can I do?
mex -setup still fails, the cause is likely your combination of Xcode and macOS versions: MATLAB expects an old version of the macOS SDK to be installed in Xcode, but this does not show up as macOS is more recent than that.
Sometimes this issue is patched by Mathworks; alternatively, you can tweak the
mex configuration file as explained above. Look for the
<SDKVER> sections of the file and add lines such as
<dirExists name="$$/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.11.sdk" /> as needed for your SDK version. Note that these are overwritten if you call
mex -setup again, so consider creating copies. You will need to perform similar changes to the corresponding CUDA configuration files.