Skip to content

Long path names break Windows build (originally: MSVC Generator can break CMake builds) #1237

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
LeonMatthesKDAB opened this issue Mar 20, 2025 · 6 comments · Fixed by #1253
Labels
⏮️ backport-candidate Change which could be backported to the stable series 🪲 bug Something isn't working 🔨 build system Issues related to integrating CXX-Qt into CMake/Cargo

Comments

@LeonMatthesKDAB
Copy link
Collaborator

During yesterdays training @narnaud could only build with the Ninja generator, not the MSVC one.

We need to investigate whether we can reproduce this and how to fix it.

@narnaud can you reproduce the error and provide us with the error message please?

@LeonMatthesKDAB LeonMatthesKDAB added 🔨 build system Issues related to integrating CXX-Qt into CMake/Cargo 🤔 discussion Feedback welcome 🪲 bug Something isn't working ⏮️ backport-candidate Change which could be backported to the stable series labels Mar 20, 2025
@narnaud
Copy link
Member

narnaud commented Mar 20, 2025

The error log is quite long, here is the beginning:

[build] CUSTOMBUILD : warning : [email protected]: ToolExecError: command did not execute successfully (status code exit code: 2): "C:/Program Files/Microsoft Visual Studio/2022/Professional/VC/Tools/MSVC/14.43.34808/bin/Hostx64/x64/cl.exe" "-nologo" "-MD" "-Z7" "-Brepro" "-std:c++17" "-I" "C:/Qt/6.8.2/msvc2022_64/include/QtQuickControls2" "-I" "C:/Qt/6.8.2/msvc2022_64/include/QtCore" "-I" "C:/Qt/6.8.2/msvc2022_64/include/QtQml" "-I" "C:/Qt/6.8.2/msvc2022_64/include/QtGui" "-I" "C:/Qt/6.8.2/msvc2022_64/include" "-I" "C:/dev/rust/training-handout/rust-cxx-qt/sol-imageviewer-cxx-qt/build/x64/Debug/cargo/build\\x86_64-pc-windows-msvc\\debug\\build\\cxx-qt-lib-bb82d48ca66ed227\\out\\cxx-qt-build\\target\\crates\\cxx-qt-lib\\include" "-I" "C:/dev/rust/training-handout/rust-cxx-qt/sol-imageviewer-cxx-qt/build/x64/Debug/cargo/build\\x86_64-pc-windows-msvc\\debug\\build\\cxx-qt-lib-bb82d48ca66ed227\\out\\cxx-qt-build\\target\\crates\\cxx-qt-lib\\include\\cxx-qt-lib-internals" "-I" "C:/dev/rust/training-handout/rust-cxx-qt/sol-imageviewer-cxx-qt/build/x64/Debug/cargo/build\\x86_64-pc-windows-msvc\\debug\\build\\cxx-qt-lib-bb82d48ca66ed227\\out/qt-build-utils/moc" "-I" "C:/dev/rust/training-handout/rust-cxx-qt/sol-imageviewer-cxx-qt/build/x64/Debug/cargo/build\\x86_64-pc-windows-msvc\\debug\\build\\cxx-qt-lib-bb82d48ca66ed227\\out/qt-build-utils/moc" "-W4" "/Zc:__cplusplus" "/permissive-" "/bigobj" "-DCXX_QT_GUI_FEATURE" "-DCXX_QT_QML_FEATURE" "-DCXX_QT_QUICKCONTROLS_FEATURE" "-FoC:/dev/rust/training-handout/rust-cxx-qt/sol-imageviewer-cxx-qt/build/x64/Debug/cargo/build\\x86_64-pc-windows-msvc\\debug\\build\\cxx-qt-lib-bb82d48ca66ed227\\out\\956f9a0767486f47-qquickstyle.cxxqt.o" "-c" "C:/dev/rust/training-handout/rust-cxx-qt/sol-imageviewer-cxx-qt/build/x64/Debug/cargo/build\\x86_64-pc-windows-msvc\\debug\\build\\cxx-qt-lib-bb82d48ca66ed227\\out\\cxx-qt-gen/src/quickcontrols/qquickstyle.cxxqt.cpp"qtimezone.cxx.cpp [C:\dev\rust\training-handout\rust-cxx-qt\sol-imageviewer-cxx-qt\build\ImageFilter\_cargo-build_image_filter.vcxproj]
[build] CUSTOMBUILD : warning : [email protected]: ToolExecError: command did not execute successfully (status code exit code: 2): "C:/Program Files/Microsoft Visual Studio/2022/Professional/VC/Tools/MSVC/14.43.34808/bin/Hostx64/x64/cl.exe" "-nologo" "-MD" "-Z7" "-Brepro" "-std:c++17" "-I" "C:/Qt/6.8.2/msvc2022_64/include/QtQuickControls2" "-I" "C:/Qt/6.8.2/msvc2022_64/include/QtCore" "-I" "C:/Qt/6.8.2/msvc2022_64/include/QtQml" "-I" "C:/Qt/6.8.2/msvc2022_64/include/QtGui" "-I" "C:/Qt/6.8.2/msvc2022_64/include" "-I" "C:/dev/rust/training-handout/rust-cxx-qt/sol-imageviewer-cxx-qt/build/x64/Debug/cargo/build\\x86_64-pc-windows-msvc\\debug\\build\\cxx-qt-lib-bb82d48ca66ed227\\out\\cxx-qt-build\\target\\crates\\cxx-qt-lib\\include" "-I" "C:/dev/rust/training-handout/rust-cxx-qt/sol-imageviewer-cxx-qt/build/x64/Debug/cargo/build\\x86_64-pc-windows-msvc\\debug\\build\\cxx-qt-lib-bb82d48ca66ed227\\out\\cxx-qt-build\\target\\crates\\cxx-qt-lib\\include\\cxx-qt-lib-internals" "-I" "C:/dev/rust/training-handout/rust-cxx-qt/sol-imageviewer-cxx-qt/build/x64/Debug/cargo/build\\x86_64-pc-windows-msvc\\debug\\build\\cxx-qt-lib-bb82d48ca66ed227\\out/qt-build-utils/moc" "-I" "C:/dev/rust/training-handout/rust-cxx-qt/sol-imageviewer-cxx-qt/build/x64/Debug/cargo/build\\x86_64-pc-windows-msvc\\debug\\build\\cxx-qt-lib-bb82d48ca66ed227\\out/qt-build-utils/moc" "-W4" "/Zc:__cplusplus" "/permissive-" "/bigobj" "-DCXX_QT_GUI_FEATURE" "-DCXX_QT_QML_FEATURE" "-DCXX_QT_QUICKCONTROLS_FEATURE" "-FoC:/dev/rust/training-handout/rust-cxx-qt/sol-imageviewer-cxx-qt/build/x64/Debug/cargo/build\\x86_64-pc-windows-msvc\\debug\\build\\cxx-qt-lib-bb82d48ca66ed227\\out\\956f9a0767486f47-qquickstyle.cxx.o" "-c" "C:/dev/rust/training-handout/rust-cxx-qt/sol-imageviewer-cxx-qt/build/x64/Debug/cargo/build\\x86_64-pc-windows-msvc\\debug\\build\\cxx-qt-lib-bb82d48ca66ed227\\out\\cxx-qt-gen/src/quickcontrols/qquickstyle.cxx.cpp" [C:\dev\rust\training-handout\rust-cxx-qt\sol-imageviewer-cxx-qt\build\ImageFilter\_cargo-build_image_filter.vcxproj]
[build] CUSTOMBUILD : error : failed to run custom build command for `cxx-qt-lib v0.7.1` [C:\dev\rust\training-handout\rust-cxx-qt\sol-imageviewer-cxx-qt\build\ImageFilter\_cargo-build_image_filter.vcxproj]
[build]   
[build]   Caused by:
[build]     process didn't exit successfully: `C:/dev/rust/training-handout/rust-cxx-qt/sol-imageviewer-cxx-qt/build/x64/Debug/cargo/build\debug\build\cxx-qt-lib-0cd847722440e25a\build-script-build` (exit code: 1)
[build]     --- stdout
[build]     cargo::rerun-if-env-changed=QMAKE
[build]     cargo::rerun-if-env-changed=QT_VERSION_MAJOR
[build]     cargo::rerun-if-changed=include/
[build]     cargo::rerun-if-changed=include/common.h
[build]     cargo::rerun-if-changed=include/assertion_utils.h
[build]     cargo::rerun-if-changed=include/core
[build]     cargo::rerun-if-changed=include/core/qanystringview.h
[build]     cargo::rerun-if-changed=include/core/qbytearray.h
[build]     cargo::rerun-if-changed=include/core/qcoreapplication.h
[build]     cargo::rerun-if-changed=include/core/qdate.h
[build]     cargo::rerun-if-changed=include/core/qdatetime.h
...

But I think the interesting part is here:

[build] C:/dev/rust/training-handout/rust-cxx-qt/sol-imageviewer-cxx-qt/build/x64/Debug/cargo/build\x86_64-pc-windows-msvc\debug\build\cxx-qt-lib-bb82d48ca66ed227\out\cxx-qt-gen/src/quickcontrols/qquickstyle.cxx.cpp(3): fatal error C1083: Cannot open include file: 'cxx-qt-lib-internals/src/quickcontrols/qquickstyle.cxxqt.h': No such file or directory [C:\dev\rust\training-handout\rust-cxx-qt\sol-imageviewer-cxx-qt\build\ImageFilter\_cargo-build_image_filter.vcxproj]
[build]     exit code: 0

@narnaud
Copy link
Member

narnaud commented Mar 21, 2025

In VS Code, to make sure you are using ninja, you need to add a .vscode/settings.json in your project with:

{
    "cmake.generator": "Ninja"
}

Or set it as a user settings and you won't have to think about it anymore.

@LeonMatthesKDAB
Copy link
Collaborator Author

Thank you, so as I remember it, the error is caused by the Cargo build script of cxx-qt-lib.
This is very strange, as those build scripts really don't have much to do with the generator, they're entirely driven by Cargo...

Maybe this has something to do with the file synchronization issues that we have encountered previously on Windows?
But it seems to be reproducable, which points to this not being the case.
Either way, we should see if we can reproduce this in CI.

@klochowicz
Copy link

klochowicz commented Mar 26, 2025

FWIW, I've just run into this issue today, and can reliably reproduce it on our (internal) GitLab CI (cxx-qt 0.7.1, msvc generator).

Will try to switch to ninja....

LeonMatthesKDAB added a commit to LeonMatthesKDAB/cxx-qt that referenced this issue Mar 31, 2025
Trying to replicate KDAB#1237.

DO NOT MERGE, as this will likely break sccache!
LeonMatthesKDAB added a commit to LeonMatthesKDAB/cxx-qt that referenced this issue Mar 31, 2025
Trying to replicate KDAB#1237.

DO NOT MERGE, as this will likely break sccache!
LeonMatthesKDAB added a commit to LeonMatthesKDAB/cxx-qt that referenced this issue Mar 31, 2025
Trying to replicate KDAB#1237.

DO NOT MERGE, as this will likely break sccache!
LeonMatthesKDAB added a commit to LeonMatthesKDAB/cxx-qt that referenced this issue Mar 31, 2025
Trying to replicate KDAB#1237.

DO NOT MERGE, as this will likely break sccache!
LeonMatthesKDAB added a commit to LeonMatthesKDAB/cxx-qt that referenced this issue Mar 31, 2025
Trying to replicate KDAB#1237.

DO NOT MERGE, as this will likely break sccache!
LeonMatthesKDAB added a commit to LeonMatthesKDAB/cxx-qt that referenced this issue Mar 31, 2025
Trying to replicate KDAB#1237.

DO NOT MERGE, as this will likely break sccache!
@LeonMatthesKDAB
Copy link
Collaborator Author

I just encountered this issue while trying to debug #1234 , but while building with Ninja!

What's even stranger, I was able to fix the issue by switching the build path from:

C:\Projekte\sol-imageviewer-cxx-qt\build\Desktop_Qt_6_9_0_MSVC2022_64bit-Debug

to:

C:\Projekte\sol-imageviewer-cxx-qt\build-debug

I have no idea why that seems to be an issue..
Maybe it's the length of the file path? But that's just a wild guess...

@LeonMatthesKDAB LeonMatthesKDAB changed the title MSVC Generator can break CMake builds Long path names break Windows build (originally: MSVC Generator can break CMake builds) Apr 9, 2025
@LeonMatthesKDAB
Copy link
Collaborator Author

It turns out that this issue is caused by the limitation of 260 character long file paths.
With MSVC it is not possible to circumvent this limitation, even if you enable long path support in Windows itself!

That means there are a few ways we can fix this issue:

  • Use a shorter path for the build directory
  • Generate shorter paths in the out/ dir in cxx-qt-build
  • If using Qt Creator, enable: Settings>CMake>Junctions for CMake (this effectively creates a 64-character symlink to the build dir)

We should ourselves work to reduce the folder nesting in the out-dir in cxx-qt-build, then we can close the issue.

@LeonMatthesKDAB LeonMatthesKDAB removed the 🤔 discussion Feedback welcome label Apr 9, 2025
LeonMatthesKDAB added a commit to LeonMatthesKDAB/cxx-qt that referenced this issue Apr 10, 2025
As described in KDAB#1237, on Windows we're sometimes hitting the 260 character limit
for filepaths.

This is mostly due to a lot of nesting by Qt Creator, Corrosion and
Cargo who all include the target triple and other configuration information in the
build path.

However, we can at least reduce the character count a little bit on our
part.

For example, for qqmlengine.cxxqt.h, the path length is now reduced by
~40 characters from:

out/cxx-qt-build/target/crates/cxx-qt-lib/include/cxx-qt-lib-internals/src/qml/qqmlengine.cxxqt.h

to now:

out/cxxqtbuild/include/private/src/qml/qqmlengine.cxxqt.h
LeonMatthesKDAB added a commit that referenced this issue Apr 11, 2025
As described in #1237, on Windows we're sometimes hitting the 260 character limit
for filepaths.

This is mostly due to a lot of nesting by Qt Creator, Corrosion and
Cargo who all include the target triple and other configuration information in the
build path.

However, we can at least reduce the character count a little bit on our
part.

For example, for qqmlengine.cxxqt.h, the path length is now reduced by
~40 characters from:

out/cxx-qt-build/target/crates/cxx-qt-lib/include/cxx-qt-lib-internals/src/qml/qqmlengine.cxxqt.h

to now:

out/cxxqtbuild/include/private/src/qml/qqmlengine.cxxqt.h
BenFordTytherington pushed a commit to BenFordTytherington/cxx-qt that referenced this issue Apr 25, 2025
As described in KDAB#1237, on Windows we're sometimes hitting the 260 character limit
for filepaths.

This is mostly due to a lot of nesting by Qt Creator, Corrosion and
Cargo who all include the target triple and other configuration information in the
build path.

However, we can at least reduce the character count a little bit on our
part.

For example, for qqmlengine.cxxqt.h, the path length is now reduced by
~40 characters from:

out/cxx-qt-build/target/crates/cxx-qt-lib/include/cxx-qt-lib-internals/src/qml/qqmlengine.cxxqt.h

to now:

out/cxxqtbuild/include/private/src/qml/qqmlengine.cxxqt.h
LeonMatthesKDAB added a commit to LeonMatthesKDAB/cxx-qt that referenced this issue Apr 28, 2025
As described in KDAB#1237, on Windows we're sometimes hitting the 260 character limit
for filepaths.

This is mostly due to a lot of nesting by Qt Creator, Corrosion and
Cargo who all include the target triple and other configuration information in the
build path.

However, we can at least reduce the character count a little bit on our
part.

For example, for qqmlengine.cxxqt.h, the path length is now reduced by
~40 characters from:

out/cxx-qt-build/target/crates/cxx-qt-lib/include/cxx-qt-lib-internals/src/qml/qqmlengine.cxxqt.h

to now:

out/cxxqtbuild/include/private/src/qml/qqmlengine.cxxqt.h
LeonMatthesKDAB added a commit to LeonMatthesKDAB/cxx-qt that referenced this issue Apr 28, 2025
As described in KDAB#1237, on Windows we're sometimes hitting the 260 character limit
for filepaths.

This is mostly due to a lot of nesting by Qt Creator, Corrosion and
Cargo who all include the target triple and other configuration information in the
build path.

However, we can at least reduce the character count a little bit on our
part.

For example, for qqmlengine.cxxqt.h, the path length is now reduced by
~40 characters from:

out/cxx-qt-build/target/crates/cxx-qt-lib/include/cxx-qt-lib-internals/src/qml/qqmlengine.cxxqt.h

to now:

out/cxxqtbuild/include/private/src/qml/qqmlengine.cxxqt.h
LeonMatthesKDAB added a commit that referenced this issue Apr 29, 2025
As described in #1237, on Windows we're sometimes hitting the 260 character limit
for filepaths.

This is mostly due to a lot of nesting by Qt Creator, Corrosion and
Cargo who all include the target triple and other configuration information in the
build path.

However, we can at least reduce the character count a little bit on our
part.

For example, for qqmlengine.cxxqt.h, the path length is now reduced by
~40 characters from:

out/cxx-qt-build/target/crates/cxx-qt-lib/include/cxx-qt-lib-internals/src/qml/qqmlengine.cxxqt.h

to now:

out/cxxqtbuild/include/private/src/qml/qqmlengine.cxxqt.h
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
⏮️ backport-candidate Change which could be backported to the stable series 🪲 bug Something isn't working 🔨 build system Issues related to integrating CXX-Qt into CMake/Cargo
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants