-
Notifications
You must be signed in to change notification settings - Fork 18k
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/link: Go referencing C + C referencing Go = duplicate symbols #11263
Comments
This is documented at http://golang.org/cmd/cgo: "Using //export in a file places a restriction on the preamble: since it is copied into two different C output files, it must not contain any definitions, only declarations. Definitions must be placed in preambles in other files, or in C source files." |
Aaah that's what that means, thank you. Let me know if you'd like a docs patch to mention the duplicate symbols consequence for clarity. |
I'm happy to look at a doc patch if you think you can make it more clear. Thanks. |
@ianlancetaylor Proposed an edit here: https://go-review.googlesource.com/#/c/11247/ |
Spell out what will happen if a declaration and definition is included in the same file, should help people who run into duplicate symbol errors and search for relevant keywords. This edit is based on opening issue #11263 erroneously. Change-Id: I0645a9433b8668d2ede9b9a3f6550d802c26388b Reviewed-on: https://go-review.googlesource.com/11247 Reviewed-by: Ian Lance Taylor <iant@golang.org>
In a recent master, combining the two examples here will yield a duplicate symbol error on build. Either example alone works fine.
Including the
//export Hello
line yields this error:Doesn't matter if the
-buildmode=c-archive
flag is included. If the//export Hello
line is removed, it works fine. If the inline C code is removed, it works fine.Scenario: I'm trying to pass a callback (function pointer) from C into a Go function and I was trying to use an inline bridge function for calling it.
The text was updated successfully, but these errors were encountered: