On Wed, Nov 20, 2019 at 4:14 AM <randomshinichi4...@gmail.com> wrote: > > While browsing the examples at https://golang.org/misc/cgo/ I noticed that a > lot of them don't actually specify `package main`. Yet all the C shared lib > tutorials say that all my exported code has to be in `package main`. > > I need to have some code translating between Go and C, do I really have to > put all of this inside package main? It's going to be a lot, or I will have > to severely restrict the functionality of the exported C interface.
For a -buildmode=c-shared build, you need to have a package main to be the root of the import tree. But your exported functions do not have to be in the main package. They can also be in any package imported by the main package. (The exported names obviously must co-exist in the C namespace, so while in Go you can have different functions with the same name in different packages, your functions exported to C must all have unique names even if they are in different packages.) Ian -- 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/CAOyqgcVf-%2B6cSE6fcOvhS64_2_FQJcxzRH6GCeuPDD9PzJ63AA%40mail.gmail.com.