/ go Public
cmd/link: trying to get a C function pointer from Go breaks if the function is stdcall #47992
Issues related to the Go compiler and/or runtime.
Someone must examine and confirm this is a valid issue and not a duplicate of an existing one.
What version of Go are you using (
Does this issue reproduce with the latest release?
What operating system and processor architecture are you using (
What did you do?
I was working over on github.com/keithcat1/gobass, adding a way for users to pass Go functions as a C callback. This involves creating a Go wrapper function which calls the user-provided callback. My problem is that BASS requires its callbacks to have the CALLBACK attribute. On windows this boils down to __stdcall.
On Windows/386 I get a linker error when trying to get the pointer to a stdcall function from Go. I think this is because stdcall functions have their name changed from for example 'add' to '_add@8' and Go can't account for this.
Here is an example:
Get either a 32-bit MinGW toolchain from something like https://www.winlibs.com Extract or LLVM MinGW, cd into the example, set GOARCH=386 and go build. If using GCC you'll get a warning about stdcall fixups, and if using Clang the linking process will fail entirely.
The way to get around this for me was to make functions that returned the C function pointers so that the C comppiler could do the right thing.
The text was updated successfully, but these errors were encountered: