在macOS上安装ocaml-top遇到GTK相关问题
conf-gtksourceview.2 Installation Error for ocaml-top on macOS High Sierra 10.13 Hey there! Let's work through that frustrating error you're seeing when trying to install ocaml-top. The conf-gtksourceview.2 failure happens because Opam can't find the GTKSourceView 2 library on your system—and since macOS High Sierra is an older release, the default Homebrew packages might not include this version anymore. Here are step-by-step fixes to get this sorted:
1. Install GTKSourceView 2 via Homebrew
First, we need to get the required GTKSourceView 2 library onto your system. Since the standard gtksourceview formula now defaults to newer versions, we'll install the legacy 2.x variant:
- Update Homebrew first (even on High Sierra, this should still work for older packages):
brew update - Install the GTKSourceView 2.x package:
brew install gtksourceview@2 - If the above command throws an error about the formula being unavailable, you can manually grab an older version of the gtksourceview formula that supports High Sierra:
- Locate a commit in the Homebrew Core formula history for gtksourceview that targets version 2.x and is compatible with macOS 10.13.
- Download the
gtksourceview.rbfile from that commit. - Install it locally with:
brew install ./gtksourceview.rb
2. Tell Opam Where to Find the Library
Once GTKSourceView 2 is installed, we need to make sure Opam's conf-gtksourceview.2 check can locate it. Set the PKG_CONFIG_PATH environment variable to point to the library's pkgconfig files:
- First, confirm the installation path with:
Look for a line likebrew info gtksourceview@2/usr/local/opt/gtksourceview@2—this is the base path. - Export the path to your shell session:
export PKG_CONFIG_PATH="/usr/local/opt/gtksourceview@2/lib/pkgconfig:$PKG_CONFIG_PATH" - Re-run the Opam install command:
opam install ocaml-top
3. Fallback: Downgrade Opam for Compatibility
If the above steps still fail, it might be because newer Opam versions aren't fully compatible with macOS High Sierra. Try downgrading to Opam 2.0.x:
- Uninstall your current Opam:
brew uninstall opam - Install the legacy Opam 2.0 package:
brew install opam@2.0 - Link it to make it the default Opam:
brew link --force opam@2.0 - Re-initialize Opam (you can keep your existing setup when prompted):
opam init eval `opam config env` - Now try installing ocaml-top again:
opam install ocaml-top
These steps should resolve the conf-gtksourceview.2 failure by either providing the missing library or ensuring Opam plays nicely with your older macOS release.
内容的提问来源于stack exchange,提问作者Jean

