4

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:

  1. 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).
  2. I have restarted my computer multiple times and confirmed that the settings are still set after restart but this has not resolved my issue.

enter image description here enter image description here enter image description here

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
Fooble
  • 485
  • 2
  • 14
  • This is likely not a CMake issue but a Windows issue. Long file path support has to be enabled. There is a Registry value you can set to enable long path names: `HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\FileSystem\LongPathsEnabled` – jkb Sep 07 '21 at 04:56
  • As I mentioned in my list of things I already tried. This AND the group policy options are both turned on. – Fooble Sep 07 '21 at 04:58
  • Sorry, didn't see that. – jkb Sep 07 '21 at 04:59
  • No problem. I expected that to work as well. I'm pulling my hair out over this – Fooble Sep 07 '21 at 05:00
  • Conan normally puts it's packages in c:\.Conan to avoid this problem https://docs.conan.io/en/latest/reference/conanfile/attributes.html#short-paths-reference. cmake does support long paths https://gitlab.kitware.com/cmake/cmake/-/issues/19675 the issue likely lies with your compiler – Alan Birtles Sep 07 '21 at 05:45
  • 1
    @AlanBirtles Looks like you were correct, its a problem with cl.exe. I have updated the question to reflect this. – Fooble Sep 07 '21 at 06:20
  • @jkb after enabling that the app still needs to opt-in to use long paths with the manifest file. The most correct solution is to add a [\\?\ suffix](https://learn.microsoft.com/en-us/windows/win32/fileio/naming-a-file?redirectedfrom=MSDN#namespaces) – phuclv Sep 07 '21 at 07:22
  • One year has passed, did you find a solution ? – Gabriel Devillers Oct 13 '22 at 12:46
  • 1
    Sadly no @GabrielDevillers I ended up just storing my conan packages in C:\.conan – Fooble Oct 14 '22 at 13:02

0 Answers0