-
Notifications
You must be signed in to change notification settings - Fork 17.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
cmd/cgo: _cgopackage.Incomplete when accessing C function starting with "union_" #68682
Comments
CC @golang/compiler |
Unfortunately, in cgo, Closing because I don't think there is anything we can do. Please comment if you disagree. |
First of all state that I'm completely new to the Go ecosystem so I may be missing something here, but isn't weird that a core library to a language so widely used just doesn't support functions starting with specific prefixes? Naively, any function that you can create in C, you should be able to use it in Go, as it's the ultimate purpose of CGo AFAIK. Also this limitation doesn't exist in other languages such as Rust ( Also I don't fully understand the issue, I understand that in CGo, you can access an union using the syntax As already stated, it feels odd that there is no workaround, if it's a design decision to not support some functions just based on the name, it should be then clearly documented. I saw this other related issue being fixed, so I just wonder why Finally, as the real use case behind this is to create a Go wrapper over a C library (meos), if in the end it's deemed as not planned, what way forward would you recommend? Since changing the C library functions names it's not a possibility. |
I agree that it was a bad choice, made many years ago. Given that choice, Go code that looks like There is a straightforward workaround: in the cgo comment, write a line Issue #28721 is a different case. That was a case where code that was never intended to be valid behaved oddly, and the solution was to ban such code. The simple way forward for your case is to use |
Thank you for providing a workaround! Maybe as a minor suggestion, somewhere in the documentation it should be stated that functions starting with some specific prefixes won't work as expected, that would avoid some debugging to some users in the future. |
Change https://go.dev/cl/602215 mentions this issue: |
For #68682 Change-Id: I13b61f915925a9ee510e0a42e95da7a83678b3b5 Reviewed-on: https://go-review.googlesource.com/c/go/+/602215 Reviewed-by: Cherry Mui <cherryyz@google.com> Auto-Submit: Ian Lance Taylor <iant@google.com> Reviewed-by: Ian Lance Taylor <iant@google.com> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Go version
go version go1.22.4 darwin/arm64
Output of
go env
in your module/workspace: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:
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:
However, when I comment the
C.union_test()
and run the following:The output is
test_union success!
. The only difference between this two function isunion_test()
starts withunion_
.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()
andC.union_test()
works properly and we can see the output:The text was updated successfully, but these errors were encountered: