go - Golang cgo compilation and run? -
i looked @ cgo example $goroot/misc/cgo/gmp shipped in go installation, , the definition in gmp.go file looks like:
package gmp /* #cgo ldflags: -lgmp #include <gmp.h> #include <stdlib.h> // gmp 5.0.0+ changed type of 3rd argument mp_bitcnt_t, // so, support older versions, wrap these 2 functions. void _mpz_mul_2exp(mpz_ptr a, mpz_ptr b, unsigned long n) { mpz_mul_2exp(a, b, n); } void _mpz_div_2exp(mpz_ptr a, mpz_ptr b, unsigned long n) { mpz_div_2exp(a, b, n); } */ import "c" import ( "os" "unsafe" )
questiones:
two c header files included here: gmp.h , stdlib.h, find these files, didn't see absolute path or relative path specified? shall install c library standard location?
how understand 2 functions here: _mpz_mul_2exp() , _mpz_div_2exp()? mean generic meaning defining function on top of cgo file?
i made go project , copied gmp.go project, having main file invoke it, got error when trying run it:
"interrupted signal: 9 sigkill".
the question how correctly compile cgo files? in cgo documentaion , mentioned use "go build" usual. suspect because don't have required c header files(gmp.h , stdlib.h), should complain "no file found" something
my env: go 1.7
goarch="amd64" gobin="" goexe="" gohostarch="amd64" gohostos="darwin" goos="darwin" gopath="/users/cnx/dev/gowork" gorace="" goroot="/usr/local/go17/go" gotooldir="/usr/local/go17/go/pkg/tool/darwin_amd64" cc="clang" gogccflags="-fpic -m64 -pthread -fno-caret-diagnostics -qunused-arguments -fmessage-length=0 -fdebug-prefix-map=/var/folders/n4/65n19xy9515_b00qv562z95w0000gq/t/go-build657965597=/tmp/go-build -gno-record-gcc-switches -fno-common" cxx="clang++" cgo_enabled="1"
thanks in advance!
Comments
Post a Comment