'Importing C library into Go with only headers, .lib/.dll/.dylib
The title basically says it all.
I need to import a 3rd party C SDK into a Go script which will be running on Alpine Linux (in a Docker container).
I have access to:
- The header files (.h)
- the .dll file that represents the SDK
- the .lib file that represents the SDK
- the .dylib file that represents the SDK
- the .so file that represents the SDK
I tried setting up the script this way:
package main
import "fmt"
// #cgo CFLAGS: -Ivendor/path/to/lib/ -g -Wall
// #include "vendor/path/to/lib/sdk.h"
import "C"
func main() {
fmt.Println("Hello World!")
}
However, I cannot import the header files this way because there are preprocessor definitions that are not handled in this scenario, see my previous question.
What are my options in this case?
Thanks!
Edit: Would building my own C program that imports the functions from the .so and then including that in my Go script instead work?
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
