Created
May 21, 2021 21:22
-
-
Save mitrofun/723620370d960dcb0dabe704166b3def to your computer and use it in GitHub Desktop.
Simple use go as lib
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import ctypes | |
| lib = ctypes.cdll.LoadLibrary('./example.dll') | |
| # use Add | |
| s = lib.Add(100, 2) | |
| print(f'Result: {s}') |
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
go build -buildmode=c-shared -o example.dll example.go
python use.py