Say that I have an object file called test.o. It contains a reference to a function called say. Also say that I have some go code:
func main() {
say()
}
Could I pass in the object file as an argument when compiling my Golang source (go build --include=test.o
), or reference it in the Go source?
So the question is: how can I access the function stored in test.o from within my Go code?
So the question is: how can I access the function stored in test.o from within my Go code?
You cannot.
Well, your question is unclear. If you have some C code compiled to some .o you can use cgo and call from go into a .so made from your .o. Read about cgo how to do it. You can compile go code so that it can be loaded dynamically during runtime. This mechanism is called plugins. All of this is complicated. The best advice is: Stop whatever you are trying and redesign. Your question smells like an XY problem. Go is compiled from source.