Blog

MCSV Compiling long paths

As of today, Visual Studio (MSVC) still has issues compiling projects with long paths. https://developercommunity.visualstudio.com/t/compiler-cant-find-source-file-in-path/10221576

I discovered this the hard way when building Qt 6.4.2 on a Windows Server 2022 machine using vcpkg and github actions. The compiler error was completely unhelpful:

C:\dev\actions-runner\_work\rose-online\rose-online\3rdparty\vcpkg\buildtrees\qtbase\x64-windows-mixed-md-dbg\include\QtPrintSupport\6.4.2\QtPrintSupport/private/qtprintsupportglobal_p.h(3): fatal error C1083: Cannot open include file: '../../../../../../src/here-src-6-a23943cb65.clean/src/printsupport/kernel/qtprintsupportglobal_p.h': No such file or directory

After banging my head against a wall for several hours trying various things (restarting the machine, applying updates, disabling anti-virus, updating all tools involved in the process such as CMake, etc.) I was getting nowhere. I had been running the build command manually from the command line to get some inspiration which includes the /showIncludes option.

C1083 error is unhelpful, the docs just fall short of saying "well it could be nearly anything": https://learn.microsoft.com/en-us/cpp/error-messages/compiler-errors-1/fatal-error-c1083?view=msvc-170

I was starting to convinced it was something with the /src/here-src-6-a23943cb65.clean/ directory. Permissions or something (despite the permissions not revealing anything).

On what must have been attempt 3000 I noticed something:

Note: including file: C:\dev\actions-runner\_work\rose-online\rose-online\3rdparty\vcpkg\buildtrees\qtbase\x64-windows-mixed-md-dbg\include\QtPrintSupport\qtprintsupportglobal.h
Note: including file:  C:\dev\actions-runner\_work\rose-online\rose-online\3rdparty\vcpkg\buildtrees\qtbase\x64-windows-mixed-md-dbg\include\QtPrintSupport\../../../src/here-src-6-a23943cb65.clean/src/printsupport/kernel/qtprintsupportglobal.h
Note: including file:   C:\dev\actions-runner\_work\rose-online\rose-online\3rdparty\vcpkg\buildtrees\qtbase\x64-windows-mixed-md-dbg\include\QtWidgets/qtwidgetsglobal.h
Note: including file:   C:\dev\actions-runner\_work\rose-online\rose-online\3rdparty\vcpkg\buildtrees\qtbase\x64-windows-mixed-md-dbg\include\QtPrintSupport/qtprintsupport-config.h
Note: including file:    C:\dev\actions-runner\_work\rose-online\rose-online\3rdparty\vcpkg\buildtrees\qtbase\x64-windows-mixed-md-dbg\include\QtPrintSupport\../../src/printsupport/qtprintsupport-config.h
Note: including file:   C:\dev\actions-runner\_work\rose-online\rose-online\3rdparty\vcpkg\buildtrees\qtbase\x64-windows-mixed-md-dbg\include\QtPrintSupport/qtprintsupportexports.h
Note: including file:    C:\dev\actions-runner\_work\rose-online\rose-online\3rdparty\vcpkg\buildtrees\qtbase\x64-windows-mixed-md-dbg\include\QtCore/qglobal.h
Note: including file: C:\dev\actions-runner\_work\rose-online\rose-online\3rdparty\vcpkg\buildtrees\qtbase\x64-windows-mixed-md-dbg\include\QtCore\qdebug.h
Note: including file: C:\dev\actions-runner\_work\rose-online\rose-online\3rdparty\vcpkg\buildtrees\qtbase\x64-windows-mixed-md-dbg\include\QtPrintSupport\6.4.2\QtPrintSupport\private/qpaintengine_alpha_p.h
Note: including file:  C:\dev\actions-runner\_work\rose-online\rose-online\3rdparty\vcpkg\buildtrees\qtbase\x64-windows-mixed-md-dbg\include\QtPrintSupport\6.4.2\QtPrintSupport\private\../../../../../../src/here-src-6-a23943cb65.clean/src/printsupport/kernel/qpaintengine_alpha_p.h
Note: including file:   C:\dev\actions-runner\_work\rose-online\rose-online\3rdparty\vcpkg\buildtrees\qtbase\x64-windows-mixed-md-dbg\include\QtPrintSupport\6.4.2\QtPrintSupport/private/qtprintsupportglobal_p.h
C:\dev\actions-runner\_work\rose-online\rose-online\3rdparty\vcpkg\buildtrees\qtbase\x64-windows-mixed-md-dbg\include\QtPrintSupport\6.4.2\QtPrintSupport/private/qtprintsupportglobal_p.h(2): fatal error C1083: Cannot open include file: '../../../../../../src/here-src-6-a23943cb65.clean/src/printsupport/kernel/qtprintsupportglobal_p.h': No such file or directory

Parsing through the the include steps I saw:

C:\dev\actions-runner\_work\rose-online\rose-online\3rdparty\vcpkg\buildtrees\qtbase\x64-windows-mixed-md-dbg\include\QtPrintSupport\../../../src/here-src-6-a23943cb65.clean/src/printsupport/kernel/qtprintsupportglobal.h

This was my breakthrough. qtprintsupportglobal.h is in the exact same directory as qtprintsupportglobal_p.h. When the first file is included, everything works fine but as we get deeper into the chain it can't include the second header...Comparing the base paths we can see a difference:

../../../src/
# vs.
../../../../../../src/

Following a hunch and recalling some past trauma with windows paths, I decided to check the length of the path for the file erroring.

261 characters

Solution: Move the build tree directory or use --x-buildtrees-root=<shorter_path>.

Thanks Visual Studio for a couple of new white hairs.