Description
Go version
go version go1.22.4 darwin/arm64
Output of go env
in your module/workspace:
GO111MODULE=''
GOARCH='arm64'
GOBIN=''
GOCACHE='/Users/wanglinhan/Library/Caches/go-build'
GOENV='/Users/wanglinhan/Library/Application Support/go/env'
GOEXE=''
GOEXPERIMENT=''
GOFLAGS=''
GOHOSTARCH='arm64'
GOHOSTOS='darwin'
GOINSECURE=''
GOMODCACHE='/Users/wanglinhan/go/pkg/mod'
GONOPROXY=''
GONOSUMDB=''
GOOS='darwin'
GOPATH='/Users/wanglinhan/go'
GOPRIVATE=''
GOPROXY='https://proxy.golang.org,direct'
GOROOT='/usr/local/go'
GOSUMDB='sum.golang.org'
GOTMPDIR=''
GOTOOLCHAIN='auto'
GOTOOLDIR='/usr/local/go/pkg/tool/darwin_arm64'
GOVCS=''
GOVERSION='go1.22.4'
GCCGO='gccgo'
AR='ar'
CC='clang'
CXX='clang++'
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 -arch arm64 -pthread -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -ffile-prefix-map=/var/folders/r_/l0_2w8jx07xg37vpsf72k0pw0000gn/T/go-build3228678536=/tmp/go-build -gno-record-gcc-switches -fno-common'
What did you do?
My colleagues(@mschoema, @Davichet-e) and I are trying to implement Go wrapper for MEOS C library, using CGO to access C function by CGO. However, we found that when a C function starts with "union_", cgo is not able to access it. Below is a minimal example:
//example.go
package main
/*
#include <stdio.h>
void union_test(){
printf("union_test success!");
}
void test_union(){
printf("test_union success!");
}
*/
import "C"
func main() {
C.test_union()
C.union_test()
}
This is two very simple C functions that print out strings, so in theory they should work. However, we see errors.
What did you see happen?
When running the go file, I got the following error:
./example.go:16:2: missing argument in conversion to cgo.Incomplete
However, when I comment the C.union_test()
and run the following:
//example.go
package main
/*
#include <stdio.h>
void union_test(){
printf("union_test success!");
}
void test_union(){
printf("test_union success!");
}
*/
import "C"
func main() {
C.test_union()
//C.union_test()
}
The output is test_union success!
. The only difference between this two function is union_test()
starts with union_
.
I think this is a bug because it means any C function starts with union_
can not be accessed by cgo. The function naming like this works in both C and Go, but not accepted by CGO. So it's very hard to make wrappers for existing geospatial C library like MEOS by CGO.
I'm not very familiar with go codebase, but the code here may be relavant.
What did you expect to see?
I expect both C.test_union()
and C.union_test()
works properly and we can see the output:
test_union success!
union_test success!