Trouble linking to system library with pkgConfig

Hello, I'm having trouble getting Swift to link to Gtk3. I do have Gtk3 installed (from Homebrew) and pkg-config does know about it:

$ pkg-config gtk+-3.0 --cflags
-D_REENTRANT -I/usr/local/Cellar/gtk+3/3.22.30/include/gtk-3.0 -I/usr/local/Cellar/glib/2.58.0/include/gio-unix-2.0/ -I/usr/local/Cellar/cairo/1.14.12/include/cairo -I/usr/local/Cellar/libepoxy/1.5.2/include -I/usr/local/Cellar/pango/1.42.4/include/pango-1.0 -I/usr/local/Cellar/harfbuzz/1.8.8/include/harfbuzz -I/usr/local/Cellar/graphite2/1.3.12/include -I/usr/local/Cellar/pango/1.42.4/include/pango-1.0 -I/usr/local/Cellar/fribidi/1.0.5/include/fribidi -I/usr/local/Cellar/atk/2.28.1_2/include/atk-1.0 -I/usr/local/Cellar/cairo/1.14.12/include/cairo -I/usr/local/Cellar/pixman/0.34.0_1/include/pixman-1 -I/usr/local/Cellar/fontconfig/2.13.1/include -I/usr/local/opt/freetype/include/freetype2 -I/usr/local/Cellar/libpng/1.6.35/include/libpng16 -I/usr/local/Cellar/gdk-pixbuf/2.36.12/include/gdk-pixbuf-2.0 -I/usr/local/Cellar/libpng/1.6.35/include/libpng16 -I/usr/local/Cellar/glib/2.58.0/include/glib-2.0 -I/usr/local/Cellar/glib/2.58.0/lib/glib-2.0/include -I/usr/local/opt/gettext/include -I/usr/local/Cellar/pcre/8.42/include

However, my Swift package (Gtk3) fails to build when I import the C system package / shim (CGtk3). I have put both of them up on github:

  • CGtk3 - here pkgConfig is setup just like the official documentation.
  • Gtk3 - just a Hello World importing CGtk3
$ git clone https://github.com/TaborKelly/Gtk3
Cloning into 'Gtk3'...
remote: Counting objects: 10, done.
remote: Compressing objects: 100% (8/8), done.
remote: Total 10 (delta 0), reused 7 (delta 0), pack-reused 0
Unpacking objects: 100% (10/10), done.
$ cd Gtk3/
$ swift build
Fetching git@github.com:TaborKelly/CGtk3.git
Cloning git@github.com:TaborKelly/CGtk3.git
Resolving git@github.com:TaborKelly/CGtk3.git at 0.1.0
Compile Swift Module 'Gtk3' (1 sources)
<module-includes>:1:9: note: in file included from <module-includes>:1:
#import "shim.h"
        ^
/Users/tabor.kelly/work/tmp/Gtk3/.build/checkouts/CGtk3.git-1657053074184707870/shim.h:4:10: error: 'gtk/gtk.h' file not found
#include <gtk/gtk.h>
         ^
/Users/tabor.kelly/work/tmp/Gtk3/Sources/main.swift:3:8: error: could not build Objective-C module 'CGtk3'
import CGtk3
       ^
error: terminated(1): /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/swift-build-tool -f /Users/tabor.kelly/work/tmp/Gtk3/.build/debug.yaml main output:

However, gtk/gtk.h is in /usr/local/Cellar/gtk+3/3.22.30/include/gtk-3.0 which pkg-config does know about (see above):

$ ll /usr/local/Cellar/gtk+3/3.22.30/include/gtk-3.0/gtk/gtk.h
-rw-r--r--  1 tabor.kelly  1294114153  9663 Apr 16 11:48 /usr/local/Cellar/gtk+3/3.22.30/include/gtk-3.0/gtk/gtk.h

These are Swift3 packages with the latest X-Code on an up-to-date MacBook Pro. Any help would be greatly appreciated.

Judging by the lack of replies I guess I didn't make some dumb mistake? Anyway, I went ahead and created a bug: SR-8715.

1 Like