我正在尝试从 python 调用 go lang 函数 当我调用我的 python 程序时,我看到以下错误。 我指的是 Go to pythn关联。
Python程序
from ctypes import *
def call_go_function():
lib = cdll.LoadLibrary("./awesome.so")
lib.Add.argtypes = [c_longlong, c_longlong]
print( lib.Add(12,99))
call_go_function()
Go程序
package main
import "C"
import (
"sync"
)
var count int
var mtx sync.Mutex
//export Add
func Add(a, b int) int { return a + b }
func main() {}
最佳答案
从 Python 路径看,这是一个 32 位 Python 版本。您不能混合使用 32 位和 64 位用户空间代码。
所以我猜你需要:
- 将您的 Go 代码重建为 32 位 DLL(参见 GOARCH=386)或
- 安装并运行 64 位 Python 版本。
关于python - 如何从 Python 调用 Go 函数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57105879/