Build error: C++ compiler produced errors. See the Build Log for further details.

Hello, I wanted to create a MEX file in MATLAB, but I couldn't do that because of the following message in the "build log":
nvcc -c -rdc=true -Xcompiler "/wd 4819" -Xcompiler "/MD" -Xcudafe "--diag_suppress=unsigned_compare_with_zero --diag_suppress=useless_type_qualifier_on_return_type" -D_GNU_SOURCE -DMATLAB_MEX_FILE -Wno-deprecated-declarations     -arch sm_35 -I "C:\PROGRA~1\MATLAB\R2018b\simulink\include" -I "C:\PROGRA~1\MATLAB\R2018b\toolbox\shared\simtargets" -I "D:\feko\multiple ring array\codegen\mex\BPmimo2C" -I "D:\feko\multiple ring array" -I ".\interface" -I "C:\PROGRA~1\MATLAB\R2018b\extern\include" -I "." "BPmimo2C_data.cu"
nvcc warning : The 'compute_35', 'compute_37', 'compute_50', 'sm_35', 'sm_37' and 'sm_50' architectures are deprecated, and may be removed in a future release (Use -Wno-deprecated-gpu-targets to suppress warning).
BPmimo2C_data.cu
nvcc -c -rdc=true -Xcompiler "/wd 4819" -Xcompiler "/MD" -Xcudafe "--diag_suppress=unsigned_compare_with_zero --diag_suppress=useless_type_qualifier_on_return_type" -D_GNU_SOURCE -DMATLAB_MEX_FILE -Wno-deprecated-declarations     -arch sm_35 -I "C:\PROGRA~1\MATLAB\R2018b\simulink\include" -I "C:\PROGRA~1\MATLAB\R2018b\toolbox\shared\simtargets" -I "D:\feko\multiple ring array\codegen\mex\BPmimo2C" -I "D:\feko\multiple ring array" -I ".\interface" -I "C:\PROGRA~1\MATLAB\R2018b\extern\include" -I "." "BPmimo2C_initialize.cu"
nvcc warning : The 'compute_35', 'compute_37', 'compute_50', 'sm_35', 'sm_37' and 'sm_50' architectures are deprecated, and may be removed in a future release (Use -Wno-deprecated-gpu-targets to suppress warning).
BPmimo2C_initialize.cu
nvcc -c -rdc=true -Xcompiler "/wd 4819" -Xcompiler "/MD" -Xcudafe "--diag_suppress=unsigned_compare_with_zero --diag_suppress=useless_type_qualifier_on_return_type" -D_GNU_SOURCE -DMATLAB_MEX_FILE -Wno-deprecated-declarations     -arch sm_35 -I "C:\PROGRA~1\MATLAB\R2018b\simulink\include" -I "C:\PROGRA~1\MATLAB\R2018b\toolbox\shared\simtargets" -I "D:\feko\multiple ring array\codegen\mex\BPmimo2C" -I "D:\feko\multiple ring array" -I ".\interface" -I "C:\PROGRA~1\MATLAB\R2018b\extern\include" -I "." "BPmimo2C_terminate.cu"
nvcc warning : The 'compute_35', 'compute_37', 'compute_50', 'sm_35', 'sm_37' and 'sm_50' architectures are deprecated, and may be removed in a future release (Use -Wno-deprecated-gpu-targets to suppress warning).
BPmimo2C_terminate.cu
nvcc -c -rdc=true -Xcompiler "/wd 4819" -Xcompiler "/MD" -Xcudafe "--diag_suppress=unsigned_compare_with_zero --diag_suppress=useless_type_qualifier_on_return_type" -D_GNU_SOURCE -DMATLAB_MEX_FILE -Wno-deprecated-declarations     -arch sm_35 -I "C:\PROGRA~1\MATLAB\R2018b\simulink\include" -I "C:\PROGRA~1\MATLAB\R2018b\toolbox\shared\simtargets" -I "D:\feko\multiple ring array\codegen\mex\BPmimo2C" -I "D:\feko\multiple ring array" -I ".\interface" -I "C:\PROGRA~1\MATLAB\R2018b\extern\include" -I "." "BPmimo2C.cu"
nvcc warning : The 'compute_35', 'compute_37', 'compute_50', 'sm_35', 'sm_37' and 'sm_50' architectures are deprecated, and may be removed in a future release (Use -Wno-deprecated-gpu-targets to suppress warning).
BPmimo2C.cu
nvcc -c -rdc=true -Xcompiler "/wd 4819" -Xcompiler "/MD" -Xcudafe "--diag_suppress=unsigned_compare_with_zero --diag_suppress=useless_type_qualifier_on_return_type" -D_GNU_SOURCE -DMATLAB_MEX_FILE -Wno-deprecated-declarations     -arch sm_35 -I "C:\PROGRA~1\MATLAB\R2018b\simulink\include" -I "C:\PROGRA~1\MATLAB\R2018b\toolbox\shared\simtargets" -I "D:\feko\multiple ring array\codegen\mex\BPmimo2C" -I "D:\feko\multiple ring array" -I ".\interface" -I "C:\PROGRA~1\MATLAB\R2018b\extern\include" -I "." "interface/_coder_BPmimo2C_info.cu"
nvcc warning : The 'compute_35', 'compute_37', 'compute_50', 'sm_35', 'sm_37' and 'sm_50' architectures are deprecated, and may be removed in a future release (Use -Wno-deprecated-gpu-targets to suppress warning).
_coder_BPmimo2C_info.cu
nvcc -c -rdc=true -Xcompiler "/wd 4819" -Xcompiler "/MD" -Xcudafe "--diag_suppress=unsigned_compare_with_zero --diag_suppress=useless_type_qualifier_on_return_type" -D_GNU_SOURCE -DMATLAB_MEX_FILE -Wno-deprecated-declarations     -arch sm_35 -I "C:\PROGRA~1\MATLAB\R2018b\simulink\include" -I "C:\PROGRA~1\MATLAB\R2018b\toolbox\shared\simtargets" -I "D:\feko\multiple ring array\codegen\mex\BPmimo2C" -I "D:\feko\multiple ring array" -I ".\interface" -I "C:\PROGRA~1\MATLAB\R2018b\extern\include" -I "." "interface/_coder_BPmimo2C_api.cu"
nvcc warning : The 'compute_35', 'compute_37', 'compute_50', 'sm_35', 'sm_37' and 'sm_50' architectures are deprecated, and may be removed in a future release (Use -Wno-deprecated-gpu-targets to suppress warning).
_coder_BPmimo2C_api.cu
nvcc -c -rdc=true -Xcompiler "/wd 4819" -Xcompiler "/MD" -Xcudafe "--diag_suppress=unsigned_compare_with_zero --diag_suppress=useless_type_qualifier_on_return_type" -D_GNU_SOURCE -DMATLAB_MEX_FILE -Wno-deprecated-declarations     -arch sm_35 -I "C:\PROGRA~1\MATLAB\R2018b\simulink\include" -I "C:\PROGRA~1\MATLAB\R2018b\toolbox\shared\simtargets" -I "D:\feko\multiple ring array\codegen\mex\BPmimo2C" -I "D:\feko\multiple ring array" -I ".\interface" -I "C:\PROGRA~1\MATLAB\R2018b\extern\include" -I "." "interface/_coder_BPmimo2C_mex.cu"
nvcc warning : The 'compute_35', 'compute_37', 'compute_50', 'sm_35', 'sm_37' and 'sm_50' architectures are deprecated, and may be removed in a future release (Use -Wno-deprecated-gpu-targets to suppress warning).
_coder_BPmimo2C_mex.cu
nvcc -c -rdc=true -Xcompiler "/wd 4819" -Xcompiler "/MD" -Xcudafe "--diag_suppress=unsigned_compare_with_zero --diag_suppress=useless_type_qualifier_on_return_type" -D_GNU_SOURCE -DMATLAB_MEX_FILE -Wno-deprecated-declarations     -arch sm_35 -I "C:\PROGRA~1\MATLAB\R2018b\simulink\include" -I "C:\PROGRA~1\MATLAB\R2018b\toolbox\shared\simtargets" -I "D:\feko\multiple ring array\codegen\mex\BPmimo2C" -I "D:\feko\multiple ring array" -I ".\interface" -I "C:\PROGRA~1\MATLAB\R2018b\extern\include" -I "." "MWCudaDimUtility.cu"
nvcc warning : The 'compute_35', 'compute_37', 'compute_50', 'sm_35', 'sm_37' and 'sm_50' architectures are deprecated, and may be removed in a future release (Use -Wno-deprecated-gpu-targets to suppress warning).
MWCudaDimUtility.cu
nvcc -c -rdc=true -Xcompiler "/wd 4819" -Xcompiler "/MD" -Xcudafe "--diag_suppress=unsigned_compare_with_zero --diag_suppress=useless_type_qualifier_on_return_type" -D_GNU_SOURCE -DMATLAB_MEX_FILE -Wno-deprecated-declarations     -arch sm_35 -I "C:\PROGRA~1\MATLAB\R2018b\simulink\include" -I "C:\PROGRA~1\MATLAB\R2018b\toolbox\shared\simtargets" -I "D:\feko\multiple ring array\codegen\mex\BPmimo2C" -I "D:\feko\multiple ring array" -I ".\interface" -I "C:\PROGRA~1\MATLAB\R2018b\extern\include" -I "." "cpp_mexapi_version.cpp"
nvcc warning : The 'compute_35', 'compute_37', 'compute_50', 'sm_35', 'sm_37' and 'sm_50' architectures are deprecated, and may be removed in a future release (Use -Wno-deprecated-gpu-targets to suppress warning).
cpp_mexapi_version.cpp
nvcc -m64 -Wl,--no-undefined -shared -static -L"C:\Program Files\MATLAB\R2018b\extern\lib\win64\mingw64" -llibmx -llibmex -llibmat -lm -llibmwlapack -llibmwblas -llibMatlabDataArray -llibMatlabEngine -Xnvlink -w -Wno-deprecated-gpu-targets -Xlinker /NODEFAULTLIB:libcmt.lib -o BPmimo2C_mex.mexw64 -arch sm_35 BPmimo2C_data.obj BPmimo2C_initialize.obj BPmimo2C_terminate.obj BPmimo2C.obj _coder_BPmimo2C_info.obj _coder_BPmimo2C_api.obj _coder_BPmimo2C_mex.obj MWCudaDimUtility.obj cpp_mexapi_version.obj -L"C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v11.2\lib\x64" cuda.lib cudart.lib cublas.lib cusolver.lib cufft.lib -Xlinker libemlrt.lib,libcovrt.lib,libut.lib,libmwmathutil.lib,/export:mexFunction,/export:emlrtMexFcnProperties 
nvcc fatal : Unknown option '-Wl,--no-undefined'
gmake: *** [BPmimo2C_mex.mexw64] Error 1
Warning: Selected MEX compiler 'MinGW64 Compiler (C++)' is not supported for GPU code generation. Refer to the GPU Coder documentation for a list of supported GPU MEX compilers. 
> In coder.gpu.getDefaultGpuToolchain
  In emlckernel
  In emlckernel
  In emlcprivate
  In coder.internal.gui.codegenWrapper
  In codeUnifiedProject
  In codeUnifiedProject
  In emlcprivate 
??? Build error: C++ compiler produced errors. See the Build Log for further details.
Code generation failed: View Error Report
I have previously installed visual studio 2019, and added the "cl.exe" path to my environmental variable. Moreover, Microsoft visual C++ redistributable x64 2015-2019 is currently available on my system.
Here is the added path:
What do you think about where my problem come from?
Any help would be appreciated.
Thank you

 Accepted Answer

You are using MinGW64 as the C++ compiler, which is not supported by nvcc. You can config it using:
mex -setup c++
and select Microsfot Visual C++ 2019.

6 Comments

Hello, thank you for your help. Actually I did what you said, but the following message was shown up:

        >> mex -setup c++
        MEX configured to use 'MinGW64 Compiler (C++)' for C++ language compilation.
        Warning: The MATLAB C and Fortran API has changed to support MATLAB
        	 variables with more than 2^32-1 elements. You will be required
        	 to update your code to utilize the new API.
        	 You can find more information about this at:
        	 https://www.mathworks.com/help/matlab/matlab_external/upgrading-mex-files-to-use-64-bit-api.html.
        To choose a different C++ compiler, select one from the following:
        MinGW64 Compiler (C++)  mex -setup:'C:\Program Files\MATLAB\R2018b\bin\win64\mexopts\mingw64_g++.xml' C++
        MinGW64 Compiler with Windows 10 SDK or later (C++)  mex -setup:'C:\Program Files\MATLAB\R2018b\bin\win64\mexopts\mingw64_g++_sdk10+.xml' C++

It looks like visual studio is not recognized for MATLAB as a compiler. But, when I check the control panel, I see it is installed. Can please tell me what should I do?

Can you try dumpling the log by running this command?
mex -setup c++ -v
It should print out lines like this:
... Looking for compiler 'Microsoft Visual C++ 2019' ...
... Looking for environment variable 'ProgramFiles(x86)' ...Yes ('C:\Program Files (x86)').
... Looking for file 'C:\Program Files (x86)\Microsoft Visual Studio\Installer\vswhere.exe' ...Yes.
Thank you @Chao Luo ,
Here is the output. It looks like it does recognize installed VS 2019:
>> mex -setup c++ -v
Verbose mode is on.
... Looking for compiler 'Intel Parallel Studio XE 2015 for C++ with Microsoft Visual Studio 2015' ...
... Looking for environment variable 'ICPP_COMPILER15' ...No.
Did not find installed compiler 'Intel Parallel Studio XE 2015 for C++ with Microsoft Visual Studio 2015'.
... Looking for compiler 'Intel Parallel Studio XE 2016 for C++ with Microsoft Visual Studio 2015' ...
... Looking for environment variable 'ICPP_COMPILER16' ...No.
Did not find installed compiler 'Intel Parallel Studio XE 2016 for C++ with Microsoft Visual Studio 2015'.
... Looking for compiler 'Intel Parallel Studio XE 2017 for C++ with Microsoft Visual Studio 2015' ...
... Looking for environment variable 'ICPP_COMPILER17' ...No.
Did not find installed compiler 'Intel Parallel Studio XE 2017 for C++ with Microsoft Visual Studio 2015'.
... Looking for compiler 'Intel Parallel Studio XE 2017 for C++ with Microsoft Visual Studio 2017' ...
... Looking for environment variable 'ICPP_COMPILER17' ...No.
Did not find installed compiler 'Intel Parallel Studio XE 2017 for C++ with Microsoft Visual Studio 2017'.
... Looking for compiler 'Intel Parallel Studio XE 2018 for C++ with Microsoft Visual Studio 2015' ...
... Looking for environment variable 'ICPP_COMPILER18' ...No.
Did not find installed compiler 'Intel Parallel Studio XE 2018 for C++ with Microsoft Visual Studio 2015'.
... Looking for compiler 'Intel Parallel Studio XE 2018 for C++ with Microsoft Visual Studio 2017' ...
... Looking for environment variable 'ICPP_COMPILER18' ...No.
Did not find installed compiler 'Intel Parallel Studio XE 2018 for C++ with Microsoft Visual Studio 2017'.
... Looking for compiler 'MinGW64 Compiler (C++)' ...
... Looking for environment variable 'MW_MINGW64_LOC' ...Yes ('C:\ProgramData\MATLAB\SupportPackages\R2018b\3P.instrset\mingw_w64.instrset').
... Looking for file 'C:\ProgramData\MATLAB\SupportPackages\R2018b\3P.instrset\mingw_w64.instrset\bin\g++.exe' ...Yes.
... Looking for folder 'C:\ProgramData\MATLAB\SupportPackages\R2018b\3P.instrset\mingw_w64.instrset' ...Yes.
... Looking for environment variable 'MW_MINGW64_LOC' ...Yes ('C:\ProgramData\MATLAB\SupportPackages\R2018b\3P.instrset\mingw_w64.instrset').
... Executing command 'C:\ProgramData\MATLAB\SupportPackages\R2018b\3P.instrset\mingw_w64.instrset\bin\g++ -dumpmachine' ...Yes ('x86_64-w64-mingw32').
... Looking for environment variable 'MW_MINGW64_LOC' ...Yes ('C:\ProgramData\MATLAB\SupportPackages\R2018b\3P.instrset\mingw_w64.instrset').
... Executing command 'C:\ProgramData\MATLAB\SupportPackages\R2018b\3P.instrset\mingw_w64.instrset\bin\g++ -dumpversion' ...Yes ('6.3.0').
Found installed compiler 'MinGW64 Compiler (C++)'.
... Looking for compiler 'MinGW64 Compiler with Windows 10 SDK or later (C++)' ...
... Looking for environment variable 'MW_MINGW64_LOC' ...Yes ('C:\ProgramData\MATLAB\SupportPackages\R2018b\3P.instrset\mingw_w64.instrset').
... Looking for file 'C:\ProgramData\MATLAB\SupportPackages\R2018b\3P.instrset\mingw_w64.instrset\bin\g++.exe' ...Yes.
... Looking for folder 'C:\ProgramData\MATLAB\SupportPackages\R2018b\3P.instrset\mingw_w64.instrset' ...Yes.
... Looking for registry setting 'HKLM\SOFTWARE\Wow6432Node\Microsoft\Microsoft SDKs\Windows\v10.0' InstallationFolder ...Yes ('F:\Windows Kits\10\').
... Looking for folder 'C:\Program Files\MATLAB\R2018b' ...Yes.
... Executing command '"C:\Program Files\MATLAB\R2018b\bin\mbuild.bat" -getWin10SDKVersion' ...Yes ('10.0.19041.0').
Found installed compiler 'MinGW64 Compiler with Windows 10 SDK or later (C++)'.
... Looking for compiler 'Microsoft Visual C++ 2013' ...
... Looking for registry setting 'HKLM\SOFTWARE\Microsoft\VisualStudio\SxS\VS7' 12.0 ...No.
... Looking for registry setting 'HKCU\SOFTWARE\Microsoft\VisualStudio\SxS\VS7' 12.0 ...No.
... Looking for registry setting 'HKLM\SOFTWARE\Wow6432Node\Microsoft\VisualStudio\SxS\VS7' 12.0 ...No.
... Looking for registry setting 'HKCU\SOFTWARE\Wow6432Node\Microsoft\VisualStudio\SxS\VS7' 12.0 ...No.
Did not find installed compiler 'Microsoft Visual C++ 2013'.
... Looking for compiler 'Microsoft Visual C++ 2015' ...
... Looking for registry setting 'HKLM\SOFTWARE\Microsoft\VisualStudio\SxS\VC7' 14.0 ...No.
... Looking for registry setting 'HKCU\SOFTWARE\Microsoft\VisualStudio\SxS\VC7' 14.0 ...No.
... Looking for registry setting 'HKLM\SOFTWARE\Wow6432Node\Microsoft\VisualStudio\SxS\VC7' 14.0 ...No.
... Looking for registry setting 'HKCU\SOFTWARE\Wow6432Node\Microsoft\VisualStudio\SxS\VC7' 14.0 ...No.
Did not find installed compiler 'Microsoft Visual C++ 2015'.
... Looking for compiler 'Microsoft Visual C++ 2017' ...
... Looking for registry setting 'HKLM\SOFTWARE\Microsoft\VisualStudio\SxS\VS7' 15.0 ...No.
... Looking for registry setting 'HKCU\SOFTWARE\Microsoft\VisualStudio\SxS\VS7' 15.0 ...No.
... Looking for registry setting 'HKLM\SOFTWARE\Wow6432Node\Microsoft\VisualStudio\SxS\VS7' 15.0 ...No.
... Looking for registry setting 'HKCU\SOFTWARE\Wow6432Node\Microsoft\VisualStudio\SxS\VS7' 15.0 ...No.
Did not find installed compiler 'Microsoft Visual C++ 2017'.
... Looking for compiler 'MinGW64 Compiler with Windows 10 SDK or later (C++)' ...
... Looking for environment variable 'MW_MINGW64_LOC' ...Yes ('C:\ProgramData\MATLAB\SupportPackages\R2018b\3P.instrset\mingw_w64.instrset').
... Looking for file 'C:\ProgramData\MATLAB\SupportPackages\R2018b\3P.instrset\mingw_w64.instrset\bin\g++.exe' ...Yes.
... Looking for folder 'C:\ProgramData\MATLAB\SupportPackages\R2018b\3P.instrset\mingw_w64.instrset' ...Yes.
... Looking for registry setting 'HKLM\SOFTWARE\Wow6432Node\Microsoft\Microsoft SDKs\Windows\v10.0' InstallationFolder ...Yes ('F:\Windows Kits\10\').
... Looking for folder 'C:\Program Files\MATLAB\R2018b' ...Yes.
... Executing command '"C:\Program Files\MATLAB\R2018b\bin\mbuild.bat" -getWin10SDKVersion' ...Yes ('10.0.19041.0').
Found installed compiler 'MinGW64 Compiler with Windows 10 SDK or later (C++)'.
MEX configured to use 'MinGW64 Compiler with Windows 10 SDK or later (C++)' for C++ language compilation.
Warning: The MATLAB C and Fortran API has changed to support MATLAB
variables with more than 2^32-1 elements. You will be required
to update your code to utilize the new API.
You can find more information about this at:
https://www.mathworks.com/help/matlab/matlab_external/upgrading-mex-files-to-use-64-bit-api.html.
To choose a different C++ compiler, select one from the following:
MinGW64 Compiler (C++) mex -setup:'C:\Program Files\MATLAB\R2018b\bin\win64\mexopts\mingw64_g++.xml' C++
MinGW64 Compiler with Windows 10 SDK or later (C++) mex -setup:C:\Users\mohammad\AppData\Roaming\MathWorks\MATLAB\R2018b\mex_C++_win64.xml C++
>>
Hello again @Chao Luo ,
these are all the applications installed on my system:
Seems you are using MATLAB 2018b. It does not support Visual Studio 2019 because it was not released when MATLAB 2018b was released. VS 2017 should be supported.

Sign in to comment.

More Answers (0)

Products

Release

R2018b

Asked:

on 24 Jun 2024

Commented:

on 28 Jun 2024

Community Treasure Hunt

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

Start Hunting!