0

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.

Jonathan Hall
  • 75,165
  • 16
  • 143
  • 189
GAP2002
  • 870
  • 4
  • 20
  • 1
    If you don’t export anything, there’s no reason to create a header file. – JimB Jan 09 '21 at 01:54
  • @JimB that's it, thanks. I need to use the //export comment to annotate functions I wish to make accessible to other languages. – GAP2002 Jan 09 '21 at 02:07

1 Answers1

0

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 () {
}
GAP2002
  • 870
  • 4
  • 20