Hello,I searched through the mailing-list and understood certain things about cgo but I want to be sure if I am correct.Cgo cannot link with static libraries (*.a files).
Cgo can only link with dynamic libraries (*.so files).go install is based on convention not configuration, so no custom Makefiles can be hooked up to the install process.I would like the user of my cgo package to do:go get github.com/.../mypackagewithout her needing to install the C libraries before.How could I achieve this?
Cgo cannot link with static libraries (*.a files).Currently, it can't.With a upcoming CL, it will get this capability, provided the static library is compiled -fPIC (e.g. CFLAGS=`go env GOGCCFLAGS`)To link a static library, you can name the static libary file by this (-lxxx won't work).#cgo LDFLAGS: libstatic.a
If your C code is simple, you can just bundle the C source with the Go source, and they will be statically linkedtogether look for example, weekly.golang.org/misc/cgo/life (it can be built simply using 'go build misc/cgo/life/main.go',and the Go tool is smart enough to compile the C code by gcc)
Thank you very much for that quick answer!Cgo cannot link with static libraries (*.a files).Currently, it can't.With a upcoming CL, it will get this capability, provided the static library is compiled -fPIC (e.g. CFLAGS=`go env GOGCCFLAGS`)To link a static library, you can name the static libary file by this (-lxxx won't work).#cgo LDFLAGS: libstatic.aisn't it : #cgo LDFLAGS: -lmylib ?
If your C code is simple, you can just bundle the C source with the Go source, and they will be statically linkedtogether look for example, weekly.golang.org/misc/cgo/life (it can be built simply using 'go build misc/cgo/life/main.go',and the Go tool is smart enough to compile the C code by gcc)The problem is that the library was created with autoconf/automake so I would prefer using libraries directly.How about copying the shared libraries into my package? Is it okay?
With a upcoming CL, it will get this capability, provided the static library is compiled -fPIC (e.g. CFLAGS=`go env GOGCCFLAGS`)