尝试编译运行 gotk3 项目的例子,发现报错:

TMBP:simple tony$ go build simple.go 
# pkg-config --cflags  -- gio-2.0 glib-2.0 gobject-2.0
Package libffi was not found in the pkg-config search path.
Perhaps you should add the directory containing `libffi.pc'
to the PKG_CONFIG_PATH environment variable
Package 'libffi', required by 'gobject-2.0', not found
pkg-config: exit status 1

看起来是缺少 libffi 这个库,于是用 brew 安装,却发现已经安装了:

TMBP:simple tony$ brew install libffi
Warning: libffi 3.2.1 is already installed and up-to-date
To reinstall 3.2.1, run `brew reinstall libffi`

于是百度了一下,发现百度的搜索结果真坑! 换用谷歌,分分钟找到重点!

参考 https://github.com/lovell/sharp/issues/1603

先看了一下确实存在这个目录: /usr/local/opt/libffi/lib/pkgconfig,于是设置环境变量:

export PKG_CONFIG_PATH="${PKG_CONFIG_PATH}:/usr/local/opt/libffi/lib/pkgconfig"

再次编译:

TMBP:simple tony$ go build simple.go 
# pkg-config --cflags  -- gdk-3.0 glib-2.0 gobject-2.0
Package gdk-3.0 was not found in the pkg-config search path.
Perhaps you should add the directory containing `gdk-3.0.pc'
to the PKG_CONFIG_PATH environment variable
No package 'gdk-3.0' found
pkg-config: exit status 1

这次说 No package 'gdk-3.0' found,也就是 gtk-3.0 没有安装,继续使用 brew 安装:

brew install gtk+3

这个安装需要安装很多额外的依赖,所以需要耐心等待。

安装中可以看到 gtk+3 的依赖包括:

==> Installing dependencies for gtk+3: gettext, openssl, sqlite, python, glib, atk, gdk-pixbuf, gsettings-desktop-schemas, hicolor-icon-theme, libepoxy, freetype, cairo, harfbuzz and pango

安装完成后再次执行编译:

TMBP:simple tony$ go build simple.go 
# command-line-arguments
ld: warning: directory not found for option '-L/usr/local/Cellar/cairo/1.16.0/lib'
ld: warning: directory not found for option '-L/usr/local/Cellar/glib/2.60.3/lib'
ld: warning: directory not found for option '-L/usr/local/Cellar/glib/2.60.3/lib'
ld: warning: directory not found for option '-L/usr/local/Cellar/pango/1.42.4_1/lib'
ld: warning: directory not found for option '-L/usr/local/Cellar/glib/2.60.3/lib'
ld: warning: directory not found for option '-L/usr/local/Cellar/cairo/1.16.0/lib'
TMBP:simple tony$ ll
total 39072
drwxr-xr-x   4 tony  staff   128B  8  6 18:36 .
drwxr-xr-x  20 tony  staff   640B  8  6 17:14 ..
-rwxr-xr-x   1 tony  staff    19M  8  6 18:36 simple
-rw-r--r--   1 tony  staff   1.1K  8  6 17:14 simple.go

报了几个 wanring,问题不大,同时看到目录下的 simple.go 已经编译好了,由于包含了 gtk 的东西,所以包的大小高达 19M

执行看看效果:

屏幕快照 2019-08-06 18.40.06.png

标签: none

添加新评论