Skip to content

Instantly share code, notes, and snippets.

@mitrofun
Created May 21, 2021 21:22
Show Gist options
  • Select an option

  • Save mitrofun/723620370d960dcb0dabe704166b3def to your computer and use it in GitHub Desktop.

Select an option

Save mitrofun/723620370d960dcb0dabe704166b3def to your computer and use it in GitHub Desktop.
Simple use go as lib
package main
import "C"
import "fmt"
func main() {}
//export Add
func Add(a int, b int) int {
fmt.Printf("Add %d with %d\n", a, b)
return a + b
}
import ctypes
lib = ctypes.cdll.LoadLibrary('./example.dll')
# use Add
s = lib.Add(100, 2)
print(f'Result: {s}')
@mitrofun

mitrofun commented May 21, 2021

Copy link
Copy Markdown
Author
  • build lib with command
    go build -buildmode=c-shared -o example.dll example.go
  • Run python
    python use.py

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment