Sitemap

Build gozk in OSX El capitan and something about Go/C interactions

robi
2 min readOct 18, 2015

Build gozk in OSX El capitan and something abount Go/C interactions

Gozk is a nice golang zookeeper client by call zookeeper raw C client — libzookeeper. Current document for gozk was about how to install on linux by goinstall..

There are some problem in OSX, but we still want to use them in local developement.

Now we will talk something to install on new OSX and using raw go get

Install libzookeeper

In OSX El capitan, try install gozk by go get will meet error

go get launchpad.net/gozk

It will stop by this error…

launchpad.net/gozk/zk.go:15:10: fatal error: ‘zookeeper.h’ file not found

#include <zookeeper.h>

^

1 error generated.

As above said…gozk is base on libzookeeper…

so we will install zookeeper first, there are many advise to use brew

brew install zookeeper

but…this’s can’t work on newest OSX..

Warning: You are using OS X 10.11.

We do not provide support for this pre-release version.

You may encounter build failures or other breakage.

==> Downloading https://www.apache.org/dyn/closer.cgi?path=zookeeper/zookeeper-3.4.6/zookeeper-3.4.6.tar.gz

Already downloaded: /Library/Caches/Homebrew/zookeeper-3.4.6.tar.gz

==> ./configure — prefix=/usr/local/Cellar/zookeeper/3.4.6_1 — without-cppunit

==> make install

2 errors generated.

make: *** [recordio.lo] Error 1

make: *** [zookeeper.jute.lo] Error 1

2 errors generated.

make: *** [zookeeper.lo] Error 1

READ THIS: https://git.io/brew-troubleshooting

Warning: You are using OS X 10.11.

We do not provide support for this pre-release version.

You may encounter build failures or other breakage.

because there is a BUG for zookeeper, so we need get 3.5.1+ zookeeper source, and build them by ourself

cd zookeeper-3.5.1-alpha/src/c

./configure — prefix=/usr/local — without-cppunit

make

make install

Make gozk use our libzookeeper

As default gozk will use self makefile as build tool..

but it’s not frendly to go get so we need do some modification and let gozk.go include and link our libzookeeper

vi $GOPATH/src/launchpad.net/gozk/zk.go

and make

#cgo CFLAGS: -I/usr/include/c-client-src -I/usr/include/zookeeper

to

#cgo CFLAGS: -I/usr/include/c-client-src -I/usr/include/zookeeper -I/usr/local/include/zookeeper

then make

#cgo LDFLAGS: -lzookeeper_mt

to

#cgo LDFLAGS: /usr/local/lib/libzookeeper_mt.a

at last, retry go get

go get launchpad.net/gozk

it’s will done..

Detail

#cgo XXX before import “C” is directive for cgo to tweek Go/C interactions

  • CFLAGS: -Ipath/to/dir will lead cgo to find C-header file in special folders
  • LDFLAGS: path/to/lib will let cgo which lib need to be link

--

--

No responses yet