Refined the causing issue, it seems to be a result of CL.exe not working with long path names. Calling cl.exe directly on a C file in a path with a long folder name results in a "file not found" error
Things I have tried:
- I have turned on long paths in both the registry and the group policy as per the instructions on the Microsoft website (https://learn.microsoft.com/en-us/windows/win32/fileio/maximum-file-path-limitation?tabs=cmd).
- I have restarted my computer multiple times and confirmed that the settings are still set after restart but this has not resolved my issue.
Here is the sample project where this issue can be seen:
C:\ReallyReallyReallyReallyReallyReallyReallyReallyReallyReallyReallyReallyReallyReallyReallyReallyReallyReallyReallyReallyReallyReallyReallyReallyReallyReallyReallyReallyReallyReallyReallyReallyReallyLongFolderName\SomeReallyReallyReallyLongSubfolderName\main.cpp
#include <iostream>
int main()
{
std::cout << "Hello, World!" << std::endl;
return 0;
}
Running dir to confirm file exists:
C:\ReallyReallyReallyReallyReallyReallyReallyReallyReallyReallyReallyReallyReallyReallyReallyReallyReallyReallyReallyReallyReallyReallyReallyReallyReallyReallyReallyReallyReallyReallyReallyReallyReallyLongFolderName\SomeReallyReallyReallyLongSubfolderName>dir
Volume in drive C has no label.
Volume Serial Number is 9A59-A85C
Directory of C:\ReallyReallyReallyReallyReallyReallyReallyReallyReallyReallyReallyReallyReallyReallyReallyReallyReallyReallyReallyReallyReallyReallyReallyReallyReallyReallyReallyReallyReallyReallyReallyReallyReallyLongFolderName\SomeReallyReallyReallyLongSubfolderName
07/09/2021 04:12 PM <DIR> .
07/09/2021 04:12 PM <DIR> ..
11/02/2021 02:22 PM 95 main.cpp
1 File(s) 95 bytes
2 Dir(s) 211,606,155,264 bytes free
Running cl.exe main.cpp:
C:\ReallyReallyReallyReallyReallyReallyReallyReallyReallyReallyReallyReallyReallyReallyReallyReallyReallyReallyReallyReallyReallyReallyReallyReallyReallyReallyReallyReallyReallyReallyReallyReallyReallyLongFolderName\SomeReallyReallyReallyLongSubfolderName>cl main.cpp
Microsoft (R) C/C++ Optimizing Compiler Version 19.28.29914 for x64
Copyright (C) Microsoft Corporation. All rights reserved.
main.cpp
c1xx: fatal error C1083: Cannot open source file: 'main.cpp': No such file or directory
C:\ReallyReallyReallyReallyReallyReallyReallyReallyReallyReallyReallyReallyReallyReallyReallyReallyReallyReallyReallyReallyReallyReallyReallyReallyReallyReallyReallyReallyReallyReallyReallyReallyReallyLongFolderName\SomeReallyReallyReallyLongSubfolderName>cl \\?\C:\ReallyReallyReallyReallyReallyReallyReallyReallyReallyReallyReallyReallyReallyReallyReallyReallyReallyReallyReallyReallyReallyReallyReallyReallyReallyReallyReallyReallyReallyReallyReallyReallyReallyLongFolderName\SomeReallyReallyReallyLongSubfolderName\main.cpp
Microsoft (R) C/C++ Optimizing Compiler Version 19.28.29914 for x64
Copyright (C) Microsoft Corporation. All rights reserved.
main.cpp
c1xx: fatal error C1083: Cannot open source file: '\\main.cpp': No such file or directory