how could i embed harfbuzz library source into go package

67 views
Skip to first unread message

aihui zhu

unread,
Dec 14, 2019, 11:19:30 PM12/14/19
to golang-nuts
I'm trying to embed the harfbuzz(http://github.com/harfbuzz/harfbuzz) library source code into go package, 
just like what the glfw(http://github.com/go-gl/glfw) library does.
The difference is that glfw contains only C, but harfbuzz is actually a C++ library and provide C API.

My cgo header code is here:

/*
#cgo CFLAGS: -Iharfbuzz/src -std=c++11 -x c++
#cgo LDFLAGS: -lstdc++

#include <stdlib.h>
#include "hb.h"
#include "hb-ot.h"
#include "harfbuzz.cc"
*/
import "C"

when i compile it, i got many errors like 
./harfbuzz.go:50:42: could not determine kind of name for C.char
./harfbuzz.go:373:20: could not determine kind of name for C.float
./harfbuzz.go:327:2: could not determine kind of name for C.free
./harfbuzz.go:97:9: could not determine kind of name for C.hb_blob_create
./harfbuzz.go:316:2: could not determine kind of name for C.hb_blob_destroy
./harfbuzz.go:325:11: could not determine kind of name for C.hb_blob_get_data
./harfbuzz.go:320:14: could not determine kind of name for C.hb_blob_get_length
./harfbuzz.go:87:84: could not determine kind of name for C.hb_blob_t

but there is no errors when i change the cgo header to use the dynamic library installed by Homebrew.

 I am not so familiar with Cgo/C++ compiling, could anyone help me.
Thanks.

aihui zhu

unread,
Dec 14, 2019, 11:47:26 PM12/14/19
to golang-nuts
Problem solved, thanks.

I created a harfbuzz.cc inside the go package directory, it contains only one line
#include "harfbuzz/src/harfbuzz.cc"

and then change the cgo header to:
/*
#cgo CFLAGS: -Iharfbuzz/src
#cgo CXXFLAGS: -std=c++11
#cgo LDFLAGS: -lstdc++

#include <stdlib.h>
#include "hb.h"
#include "hb-ot.h"
*/
import "C"


Reply all
Reply to author
Forward
0 new messages