为何用Haskell/Stack编译GTK(gi-gtk)应用无法复现成功?
Hey there! I’ve worked through similar cross-distro build headaches with gi-gtk and Stack, so let’s break down what might be tripping you up and how to fix it.
1. Double-Check System Dependencies (You Might’ve Missed a Critical One)
elementary OS is Ubuntu-based, so its package names for GTK and gobject-introspection tools differ from Fedora. Even if you fixed some missing dependencies, you could be missing a dev package that gi-gtk relies on under the hood. Run these commands to cover all bases:
sudo apt update sudo apt install libgtk-3-dev libgirepository1.0-dev gir1.2-gtk-3.0 libcairo2-dev libpango1.0-dev
These packages cover core GTK libraries, gobject-introspection bindings, and supporting tools like Cairo/Pango that gi-gtk often depends on.
2. Resolver & System Library Compatibility
You’re using lts-9.2, which ships with GHC 8.0.2—this is a fairly old resolver. elementary OS’s default GTK 3 version might have subtle API differences that clash with the gi-gtk version pinned in lts-9.2. Try two quick fixes here:
- Use your system’s GHC instead of Stack’s bundled one: If you have GHC 8.0.2 installed on elementary OS, build with:
This avoids mismatches between Stack’s compiled GHC and your system’s library paths.stack build --system-ghc - Try a slightly newer resolver (if your code allows it): Switching to lts-12.x (which supports GHC 8.4.x and has more up-to-date gi-gtk bindings) might resolve compatibility gaps. Update the
resolverfield in yourstack.yaml, then re-runstack setup && stack build.
3. Refresh GObject-Introspection Cache
gi-gtk uses gobject-introspection to bind to GTK, and sometimes the system’s introspection cache gets out of sync. Refresh it with:
sudo update-gir-cache -f
This can fix "missing module" errors even if all required packages are installed.
4. Wipe Stack’s Cache and Start Fresh
Corrupted build artifacts or cached dependencies from your Fedora setup can cause weird, hard-to-trace failures. Clean everything up with:
stack clean stack purge
Then re-run stack setup and stack build from scratch—this ensures you’re starting with a completely fresh environment tailored to elementary OS.
Pro Tip: Share the Exact Error Message
If none of these work, the specific compile error (whether it’s a linker failure, missing module, or version mismatch) will make troubleshooting way faster. Linker errors usually point to missing system libraries, while module errors relate to gobject-introspection or package version conflicts.
内容的提问来源于stack exchange,提问作者Adam Głowacki

