Repeat of post on Stack Overflow: https://stackoverflow.com/questions/78786971/why-do-some-fields-in-the-go-structs-generated-using-cgo-become-anonymous
On Wednesday, July 24, 2024 at 8:29:39 AM UTC-4 飞舟 wrote: > I have a C struct, and when I use cgo to generate Go structs, some fields > are being ignored. I’m using go version go1.21.1 linux/amd64, and here is > my env. > > go env: > > GO111MODULE='on' > GOARCH='amd64' > GOBIN='' > GOCACHE='/root/.cache/go-build' > GOENV='/root/.config/go/env' > GOEXE='' > GOEXPERIMENT='' > GOFLAGS='' > GOHOSTARCH='amd64' > GOHOSTOS='linux' > GOINSECURE='' > GOMODCACHE='/root/go/pkg/mod' > GONOPROXY='' > GONOSUMDB='' > GOOS='linux' > GOPATH='/root/go' > GOPRIVATE='' > GOPROXY='https://goproxy.cn,direct' > GOROOT='/usr/local/go' > GOSUMDB='sum.golang.org' > GOTMPDIR='' > GOTOOLCHAIN='auto' > GOTOOLDIR='/usr/local/go/pkg/tool/linux_amd64' > GOVCS='' > GOVERSION='go1.21.1' > GCCGO='gccgo' > GOAMD64='v1' > AR='ar' > CC='gcc' > CXX='g++' > CGO_ENABLED='1' > GOMOD='/dev/null' > GOWORK='' > CGO_CFLAGS='-O2 -g' > CGO_CPPFLAGS='' > CGO_CXXFLAGS='-O2 -g' > CGO_FFLAGS='-O2 -g' > CGO_LDFLAGS='-O2 -g' > PKG_CONFIG='pkg-config' > GOGCCFLAGS='-fPIC -m64 -pthread -Wl,--no-gc-sections -fmessage-length=0 > -ffile-prefix-map=/tmp/go-build2970417006=/tmp/go-build > -gno-record-gcc-switches' > > and this is my C struct: > typedef struct PicHead > { > unsigned short flag; > unsigned char version[16]; > unsigned int headSize; > int64_t fileSize; > unsigned int macrograph; > unsigned int personInfor; > unsigned int hierarchy; > unsigned int srcWidth; > unsigned int srcHeight; > unsigned int sliceWidth; > unsigned int sliceHeight; > unsigned int thumbnailWidth; > unsigned int thumbnailHeight; > unsigned char bpp; > unsigned char quality; > J_COLOR_SPACE colrSpace; > float scale; > double ruler; > unsigned int rate; > long long extraOffset; > long long tileOffset; > ImageFormat sliceFormat; > unsigned char headSpace[48]; > }PicHead; > > this is cgo gen > type _Ctype_struct_PicHead struct { > flag _Ctype_ushort > version [16]_Ctype_uchar > _ [40]byte > bpp _Ctype_uchar > quality _Ctype_uchar > colrSpace _Ctype_J_COLOR_SPACE > scale _Ctype_float > _ [8]byte > rate _Ctype_uint > extraOffset _Ctype_longlong > tileOffset _Ctype_longlong > sliceFormat _Ctype_ImageFormat > headSpace [48]_Ctype_uchar > } > -- 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+unsubscr...@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/golang-nuts/cd2d5a83-267c-4bc0-9e6f-0ee7fefbf499n%40googlegroups.com.