If it has been compiled with -buildmode=c-archive, it can not be linked to the go main package again with CGO
Could you advise how to link the archive from -buildmode=archive to a C program? Then is it possible to link the c archive from gcc to the go main package using cgo?
I have no clue. I do not use such archives. For me they ever have been a measure of “reverse FFI”. I do not care for them. I just told you what I found in a very shallow google research.
But perhaps we have an XY problem here… What exactly do you want to achieve? Why do you want to link to the archive?
A golang static library without source code to be linked to another golang main package.
Why:
The library is the key part of our work and we do not want it open source for the extension developers. And shared library is not recommended for security (preventing someone from compiling another program based on the shared library) and easy distribution.
Golang had binary only packages since go 1.7 as an experimental feature, which would support exactly what you are asking for, though support has been dropped a couple of versions later (https://github.com/golang/go/issues/28152).
Perhaps you can redesign your “key component” in a way that consumers write plugins, instead of calling your code.
From my understanding of cgo, you should be able to use the files generated, though you need to write another go file, that wraps the c-headers in a go package.
Thanks. Putting extended work into a plugin seems an acceptable solution for Linux, and macOS. But our app is cross-platform one using gioui for iOS and Android, too, and plugin does not work any more.