In the Flatpak the MinGW sysroot is the host's /usr, which puts glibc's headers on the Windows include path #43
Labels
No labels
bug
claude:blocked
claude:done
claude:failed
claude:in-progress
claude:ready
documentation
duplicate
enhancement
good first issue
help wanted
invalid
question
wontfix
bug
duplicate
enhancement
help wanted
invalid
question
wontfix
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
Catcrafts/Crafter.Build#43
Loading…
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Summary
Inside the Flatpak, a MinGW C++ program that uses
std::shared_ptrdoesn't link:The MinGW sysroot crafter-build picks there is the host's
/usr, and clang's MinGW driver adds<sysroot>/includewhenever--sysrootis given. That puts the host's glibc headers last on the include path of a Windows build. libstdc++'s<ext/atomicity.h>checks__has_include(<sys/single_threaded.h>), finds glibc's copy, and hasshared_ptr's reference counting read::__libc_single_threaded, which nothing on Windows defines.Line numbers refer to
909e027. Seen with crafter-build 4.0.0 (clang 23.1.2) on an Arch host with mingw-w64 14.0.0 and mingw-w64-gcc 16.2.0.Details
implementations/Crafter.Build-Toolchain.cpp:138-144: withoutCRAFTER_MINGW_DIR, a sandboxed run setsmingwSysroot = hostRoot / "usr"when the host has/usr/x86_64-w64-mingw32.--sysrootfor C (implementations/Crafter.Build-Clang.cpp:931-933) and C++ (implementations/Crafter.Build-Platform.cpp:867), and-DCMAKE_SYSROOTfor CMake externals (implementations/Crafter.Build-External.cpp:152).clang++ --target=x86_64-w64-mingw32 -stdlib=libstdc++ --sysroot=/run/host/usrends with the host's own headers:MinGW's own headers come first, so only headers MinGW lacks resolve to Linux's. A
__has_includeof a Linux-only header then answers yes for Windows.sys/single_threaded.his the case that breaks the link.Reproduction
In
flatpak run --command=sh net.catcrafts.CrafterBuild:clang++ --target=x86_64-w64-mingw32 -stdlib=libstdc++ -fuse-ld=lld --sysroot=/run/host/usr t.cpp -o t.exefails with the error above.In practice it stops Crafter.Graphics' Win32 executables. Crafter.Asset's GLB loader includes nlohmann/json, whose
shared_ptrcode inCrafter.Asset-GLB_impl.oended up in every one built so far: thePointerWin32andTextWin32tests, andexamples/HelloUI. Those tests have needed an archive definingchar __libc_single_threaded = 0;to link.Suggested fix
Pass a sysroot that has MinGW's layout without the host's
include/. A directory holding only two symlinks did it here:With
--sysroot=<dir>, clang found the same libstdc++ and MinGW headers,sys/single_threaded.hwas no longer visible, and the program above linked. crafter-build could make that directory in its cache once and use it wherevermingwSysrootgoes now.Two simpler options don't work.
--sysroot=/run/host/usr/x86_64-w64-mingw32loses libstdc++'s versioned header directory, so<string>is not found.--gcc-toolchain=and--gcc-install-dir=are ignored for this target ("argument unused during compilation").