kitech/qt.go

go build failed with "'ffi.h' file not found"

ipfans opened this issue · 5 comments

I already installed libffi by Homebrew, but I still got error about fatal error: 'ffi.h' file not found

Requirement information

$ brew info libffi
libffi: stable 3.2.1 (bottled), HEAD [keg-only]
Portable Foreign Function Interface library
https://sourceware.org/libffi/
/usr/local/Cellar/libffi/3.2.1 (16 files, 297.0KB)
  Poured from bottle on 2018-02-23 at 15:59:29
From: https://github.com/Homebrew/homebrew-core/blob/master/Formula/libffi.rb
==> Options
--HEAD
	Install HEAD version
==> Caveats
This formula is keg-only, which means it was not symlinked into /usr/local,
because some formulae require a newer version of libffi.

For compilers to find this software you may need to set:
    LDFLAGS:  -L/usr/local/opt/libffi/lib
For pkg-config to find this software you may need to set:
    PKG_CONFIG_PATH: /usr/local/opt/libffi/lib/pkgconfig

BUILD LOGS

$ CFLAGES=-I/usr/local/opt/libffi/lib/libffi-3.2.1/include LDFLAGS=-L/usr/local/opt/libffi/lib go run button.go
# github.com/kitech/qt.go/qtrt
../../Developer/pkg/src/github.com/kitech/qt.go/qtrt/ffi_invoke.go:10:10: fatal error: 'ffi.h' file not found
#include "ffi.h"
         ^~~~~~~
1 error generated.

另外安装教程里没有提到额外依赖 github.com/gonuts/dl,这个需要额外安装,可能需要在安装步骤中额外添加。

Getting the same error (OSX).

try: the CGO_ prefix

CGO_CFLAGES="-I/usr/local/opt/libffi/lib/libffi-3.2.1/include" CGO_LDFLAGS="-L/usr/local/opt/libffi/lib" go run button.go

The CGO_prefix doesn't fix this issue on OSX.

I see, it's a simple typo, should be CGO_CFLAGS not CGO_CFLAGES.

@AllenDang

Perhaps a bit off topic; do you know how to embed the CFLAGS and LDFLAGS in a #cgo psuedo directive?

I've tried:

// #cgo CFLAGS: -I/usr/local/opt/libffi/lib/libffi-3.2.1/include
// #cgo LDFLAGS: -L/usr/local/opt/libffi/lib

and go build fails with same error as before.

thx all