loadlibrary: 'cl' is not recognized....

15 views (last 30 days)
Troy Raker
Troy Raker on 2 Feb 2012
I'm trying to load a *.dll that was compiled with Microsoft Visual C++ 2008. I've downloaded & installed Microsoft Visual C++ 2008 Express and selected it wit mex setup. When I run loadlibrary, I get the error: "'cl' is not recognized as an internal or external command, operable program or batch file."
>> mex -setup Please choose your compiler for building external interface (MEX) files:
Would you like mex to locate installed compilers [y]/n? y
Select a compiler: [1] Microsoft Visual C++ 2010 in c:\Program Files (x86)\Microsoft Visual Studio 10.0 [2] Microsoft Visual C++ 2008 Express in C:\Program Files (x86)\Microsoft Visual Studio 9.0
[0] None
Compiler: 2
Please verify your choices:
Compiler: Microsoft Visual C++ 2008 Express Location: C:\Program Files (x86)\Microsoft Visual Studio 9.0
Are these correct [y]/n? y
*************************************************************************** Error: Could not find the 64-bit compiler. This may indicate that the "X64 Compilers and Tools" or the Microsoft Windows Software Development Kit (SDK) is not installed. To build 64-bit MEX-files Microsoft Visual C++ 2008 Express Edition requires that these two packages are installed properly. ***************************************************************************
Trying to update options file: C:\Users\traker\AppData\Roaming\MathWorks\MATLAB\R2010b\mexopts.bat From template: C:\PROGRA~1\MATLAB\R2010b\bin\win64\mexopts\msvc90freeopts.bat
Done . . .
************************************************************************ Warning: The MATLAB C and Fortran API has changed to support MATLAB variables with more than 2^32-1 elements. In the near future you will be required to update your code to utilize the new API. You can find more information about this at: http://www.mathworks.com/support/solutions/en/data/1-5C27B9/?solution=1-5C27B9 Building with the -largeArrayDims option enables the new API. ************************************************************************
>> loadlibrary(Dll,Hfile) ??? Error using ==> loadlibrary at 365 Failed to preprocess the input file. Output from preprocessor is:'cl' is not recognized as an internal or external command, operable program or batch file.

Answers (2)

Walter Roberson
Walter Roberson on 2 Feb 2012
Was the dll compiled for 32 bit or for 64 bit?
You are using 64 bit MATLAB, which can only compile 64 bit interfaces and only load 64 bit dll's. In order to work it needs the SDK 7.1 installed (which you do not have installed it appears.)
If you need to load a 32 bit dll, then you need to install the 32 bit version of MATLAB and use that; you will need to mex -setup while you are running that as it needs to build a 32-bit specific options file.

Troy Raker
Troy Raker on 3 Feb 2012
The *.dll was compiled for 64 bit.
We loaded Visual Studio 2008 Professional Edition and this seemed to eliminate the error about finding the 64-bit complier. However it did not show up on the list of available compliers when we executed the mex -setup. In the end though, we still could not load the *.dll.
>> mex -setup
Please choose your compiler for building external interface (MEX) files:
Would you like mex to locate installed compilers [y]/n?
Select a compiler:
[1] Microsoft Visual C++ 2010 in c:\Program Files (x86)\Microsoft Visual Studio 10.0
[2] Microsoft Visual C++ 2008 Express in C:\Program Files (x86)\Microsoft Visual Studio 9.0
[0] None
Compiler: 2
Please verify your choices:
Compiler: Microsoft Visual C++ 2008 Express
Location: C:\Program Files (x86)\Microsoft Visual Studio 9.0
Are these correct [y]/n?
***************************************************************************
Warning: MEX-files generated using Microsoft Visual C++ 2008 require
that Microsoft Visual Studio 2008 run-time libraries be
available on the computer they are run on.
If you plan to redistribute your MEX-files to other MATLAB
users, be sure that they have the run-time libraries.
***************************************************************************
Trying to update options file: C:\Users\traker\AppData\Roaming\MathWorks\MATLAB\R2010b\mexopts.bat
From template: C:\PROGRA~1\MATLAB\R2010b\bin\win64\mexopts\msvc90freeopts.bat
Done . . .
**************************************************************************
Warning: The MATLAB C and Fortran API has changed to support MATLAB
variables with more than 2^32-1 elements. In the near future
you will be required to update your code to utilize the new
API. You can find more information about this at:
http://www.mathworks.com/support/solutions/en/data/1-5C27B9/?solution=1-5C27B9
Building with the -largeArrayDims option enables the new API.
**************************************************************************
>> loadlibrary(Dll,Hfile)
??? Error using ==> loadlibrary at 365
Failed to preprocess the input file.
Output from preprocessor is:'cl' is not recognized as an internal or external command,
operable program or batch file.
  4 Comments
Troy Raker
Troy Raker on 7 Feb 2012
Even though the compiler error is gone, we still get the error "Failed to preprocess the input file. Output from preprocessor is:'cl' is not recognized as an internal or external command, operable program or batch file."
I've checked and there is a cl.exe in
C:\Program Files (x86)\Microsoft Visual Studio 9.0\VC\bin\amd64. We also added this to Matlab's path, but we still get the same error.
Alfredo
Alfredo on 12 Mar 2013
I got the same error, the problem was that the path to cl.exe was not in PATH environment variable for 64-bit cl.exe. In another case, this path was added "after" the path to the 32-bit version of cl.exe, so the system would find the 32-bit version first, and I would get some platform incompatibility error. So make sure you add the correct version path to PATH. For 64-bit: C:\Program Files (x86)\Microsoft Visual Studio 9.0\VC\bin\amd64

Sign in to comment.

Categories

Find more on Troubleshooting in MATLAB Compiler SDK in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!