gogo-build

build, buildmode=c does not give header file


I'm trying to build a Go package with the build flag -buildmode=c-shared. I'm expecting to get two files myfile.so and myfile.h. However, I'm only getting the .so file. Why is this and how can I fix it?

The full command I am running is:

go build -o myfile.so -buildmode=c-shared myfile.go

I found my "instructions" here as I am planning on calling myfile from Python.

This is my Go code:

package main


import (
    "C"
    "bytes"
    "log"
    "encoding/json"
    "net/http"
)



func call_request(arg1, arg2, arg3 string) {
// simple golang code to submit a http post request
    }

func main () {
}

This is a basic summary of my code, without posting my whole code. However, it may be useful to note that running the example in the link above created a .so and .h file.


Solution

  • As @JimB said, the issue was there was not a header file:

    Updated code:

    package main
    
    
    import (
        "C"
        "bytes"
        "log"
        "encoding/json"
        "net/http"
    )
    
    
    //export call_request
    func call_request(arg1, arg2, arg3 string) {
    // simple golang code to submit a http post request
        }
    
    func main () {
    }