See also, http://libraryofalexandria.io/cgo/
cgo
has a lot of trap.
but Not "C" pkg also directory in $GOROOT/src
. IDE's(vim) Goto command not works.
So, Here collect materials.
.c
, .s
, .S
.cc
, .cpp
, .cxx
Any .h
, .hh
, .hpp
, .hxx
files will not be compiled separately.
but, if these header files are changed, the C and C++ files will be recompiled.
CC
, CXX
, CC_FOR_TARGET
, CXX_FOR_TARGET
CGO_CFLAGS
, CGO_CPPFLAGS
, CGO_CXXFLAGS
, CGO_LDFLAGS
// Go string to C string; result must be freed with C.free
func C.CString(string) *C.char
// C string to Go string
func C.GoString(*C.char) string
// C string, length to Go string
func C.GoStringN(*C.char, C.int) string
// C pointer, length to Go []byte
func C.GoBytes(unsafe.Pointer, C.int) []byte
type C.char
type C.schar (signed char)
type C.uchar (unsigned char)
type C.short
type C.ushort (unsigned short)
type C.int
type C.uint (unsigned int)
type C.long
type C.ulong (unsigned long)
type C.longlong (long long)
type C.ulonglong (unsigned long long)
type C.float
type C.double
As in C.struct_stat
type C.struct_***
type C.union_***
type C.enum_***
See also https://golang.org/pkg/unsafe/
func unsafe.Pointer() *ArbitraryType
Hi,
Thanks for this. I faced with a problem lately. C.char in some platform is signed by default whereas in some others it is unsigned. so I faced with this error when trying to use C.GoString function:
cannot use _Cfunc_myfunc() (type *_Ctype_uchar) as type _Ctype_char in argument to _Cfunc_GoString
It turned out that myfunc() which return char translated to uchar instead of char. do you know how to force the cgo to deal with it?