1

I am trying to call go lang function from python when I call my python program I am seeing the following error. I am referring to the Go to pythn link.

error

Python Program

    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 Program

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() {}
2
  • 1
    You are using Windows, the tutorial you are following uses Linux/Unix. Perhaps you can apply the tutorial in a Docker container or VM. Commented Jul 19, 2019 at 6:49
  • 3
    Please don't include images of text. They are hard to read (and impossible to read if you rely on a screen reader), and they are not searchable and cannot be indexed. Instead, copy and paste the text directly into the question. Commented Jul 19, 2019 at 8:42

2 Answers 2

2

From the Python path it looks like this is a 32-bit Python version. You cannot mix 32-bit and 64-bit user-space code.

So I guess you need to either:

  • Rebuild your Go code as a 32-bit DLL (see GOARCH=386) or
  • Install and run a 64-bit Python version.
Sign up to request clarification or add additional context in comments.

Comments

1

Maybe it's an environment. Try running a simple program.

from ctypes import *
lib = cdll.LoadLibrary("./func.so")
r=lib.fun(10,20)
print(r)
package main
import "C"
//export fun
func fun(x int,y int) int{
    return x+y
}

func main(){}
>go build -o func.so -buildmode=c-shared func.go
>python test.py
30

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.