mex can't find Visual Studio 2022 C++ when running clibgen.ge​nerateLibr​aryDefinit​ion

29 Ansichten (letzte 30 Tage)
>> internal.cxxfe.util.getMexCompilerInfo
'C:\Program' is not recognized as an internal or external command,
operable program or batch file.
'cl' is not recognized as an internal or external command,
operable program or batch file.
I have reinstalled VS 2022 to a path that isn't even in C:\Program Files. Rerun mex -setup C++. Over the last week, this was working for other DLL's, but I had to recompile a DLL written for VS 2013 which Matlab doesn't support and went from 32 bit to 64 bit because the libary version of QT had to change from 5.7 to 6.7 to support VS 2022 instead of VS 2013. So now the DLL is now x64 compiled in VS 2022 with QT 6.7 using Matlab R2023b 64 bit.
  1 Kommentar
prabhat kumar sharma
prabhat kumar sharma am 2 Mai 2024
can you check that your version of MATLAB officially supports Visual Studio 2022. MATLAB support for compilers is version-specific. You can check the MathWorks documentation or the mex -setup C++ compatibility list to confirm this.

Melden Sie sich an, um zu kommentieren.

Antworten (1)

Sanchari
Sanchari am 8 Jul. 2024
Hello John,
It looks like MATLAB is unable to recognize the Visual Studio 2022 compiler for building .MEX files. This can be due to several factors, including environment variable settings, MATLAB configuration, and potential conflicts between different versions of Visual Studio or MATLAB. Here are some steps to follow for troubleshooting and resolving this:
A. Verify Environment Variables
Ensure that the "cl.exe" compiler from Visual Studio is available in the system's "PATH" environment variable.
1. Open a Command Prompt and run the following command to check if "cl.exe" is accessible:
cl
If the output is " 'cl' is not recognized as an internal or external command", it means the "PATH" is not set correctly.
2. Set the "PATH": Open Visual Studio Developer Command Prompt for VS 2022. This ensures that all necessary environment variables are set correctly. Alternatively, there is an option to manually add the path (of "cl.exe") to the system's "PATH" environment variable. The path typically looks like this, "C:\Program Files\Microsoft Visual Studio\2022\Community\VC\Tools\MSVC\14.29.30133\bin\Hostx64\x64".
To add it to the "PATH", navigate to Control Panel > System and Security > System > Advanced system settings > Environment Variables. Edit the Path variable and add the path to "cl.exe".
B. Reconfigure MATLAB mex compiler
After setting the PATH, reconfigure MATLAB to use the correct compiler. Open MATLAB and run the following command:
mex -setup C++
Ensure that MATLAB detects the Visual Studio 2022 compiler and selects it.
C. Check Compatibility
Ensure that the versions of MATLAB, Visual Studio, and any other dependencies (like QT) are compatible with each other. MATLAB R2023b should support Visual Studio 2022. Please re-verify this from the MATLAB Supported Compilers page.
D. Clean up previous configurations
If the compiler had been changed or Visual Studio been reinstalled recently, there might be residual configurations causing conflicts. Clean up previous configurations by deleting the "mexopts.bat" file if it exists in the MATLAB preferences directory. For achieving this, navigate to the directory by typing the following command and delete "mexopts.bat" file.
prefdir
Then, reset MATLAB path by typing the following set of commands in command line:
restoredefaultpath;
rehash toolboxcache;
savepath;
E. Test with a simple .MEX file
Create a simple C++ file named "simple_mex.cpp":
#include "mex.h"
void mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[])
{ mexPrintf("Hello, world!\n");
}
Compile and run the .MEX file in MATLAB using the following commands:
mex simple_mex.cpp
simple_mex
The output would look like this:
Hope this helps!

Kategorien

Mehr zu MATLAB Compiler finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by