Msvc link.exe not found

I am using python pip install, which calls, and uses distutils, to compile and link C/C++ sources. The code calls Microsoft Visual Studio C (msvc) cl.exe to compile the sources, and that works fine, but when it calls link.exe, it fails with “No such file or directory”. I ran a “dir” and found that cl, lib, and link are all located at:
C:\Program Files (x86)\Microsoft Visual Studio\2017\BuildTools\VC\Tools\MSVC\14.16.27023\bin\HostX86\x64
The code and results can be found here:

1 Like

You prob need to load vcvarsall.bat as shown in NMake support from Windows

Hello tanzislam,
thanks for replying and pointing me to Nmake! I will definitely take a look at it. However, since the project already uses python, pip, and distutils, it looks like a big change. On the other hand, I discovered something today that we need to take care of. The many calls to cl.exe that work are almost the same as the call to link.exe, but that last one is a command that is 42061 bytes long, so it is too long for Windows. I think we might need to change the python code to put that big long list of object files in a file instead of the command line, i.e. use a command file.

No, I meant that you need to load vcvarsall.bat in a cmd.exe instance (to prepare the necessary environment variables), followed by calling link.exe (or any other utility from the MSVC Build Tools). I pointed to that answer as an example of how to use vcvarsall.bat, not about how to use nmake.

But yes, I agree the problem may really be with the long command line.

Thanks again for the help. This problem has now been resolved.
I can see that there are many ways to avoid the link.exe command that exceeds 32k in length, but some of them would require changing components that we don’t normally change. In our case, the problem involved libSBML. Here is how we solved it:
First, we note that there is a compiled binary for python-libSBML for python version 3.7, but not for 3.8. So, we changed the python version and installed python-libSBML explicitly. That way, when python setup finds the dependency, it no longer tries to compile all of libSBML.

This is a problem with Python’s distutils then. It should use an auxiliary file to pass arguments to MSVC if the resulting line is too long as per