is a zlib library in Go, but I needed some advanced functionality only the
C version provides), but I was unable to compile my test program. When I
try to compile I get the following error:
# command-line-arguments
1: error: 'inflateInit' undeclared (first use in this function)
1: note: each undeclared identifier is reported only once for each function
it appears in
On the interwebs, it seems the most common issue with undeclared functions
is due to incorrectly included headers, but I think I have done so
correctly:
// #cgo LDFLAGS: -lz
// #include "zlib.h"
import "C"
Does anyone know why the following block fails to compile?
var strm C.z_stream
strm.zalloc = C.alloc_func(unsafe.Pointer(uintptr(C.Z_NULL)))
strm.zfree = C.free_func(unsafe.Pointer(uintptr(C.Z_NULL)))
strm.opaque = C.voidpf(uintptr(C.Z_NULL))
strm.avail_in = 0
strm.next_in = (*C.Bytef)(unsafe.Pointer(uintptr(C.Z_NULL)))
zerr(C.inflateInit(&strm)) // Fails here due to inflateInit not being
declared.
defer C.inflateEnd(&strm)
I'm fairly sure the zlib.h header is being included. If I remove the
inflateInit call, it compiles properly even though there are references to
other functions and structs in zlib.h like inflateEnd and z_stream. I
should note that if I create a C source wrapper around all the functions I
use, and then use the wrapper functions in Cgo, it magically works.
Is this a bug in cgo?
Thanks.
--
You received this message because you are subscribed to the Google Groups "golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.