Skip to content

Instantly share code, notes, and snippets.

@FiloSottile
Created July 17, 2016 19:48
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save FiloSottile/0fb29da70f3f45cc719b6e311e2f59ee to your computer and use it in GitHub Desktop.
Save FiloSottile/0fb29da70f3f45cc719b6e311e2f59ee to your computer and use it in GitHub Desktop.
Import Go from Python the "right" way
go build -buildmode=c-archive .
python hello_build.py
python -c "import _hello; _hello.lib.Hello()"
package main
import "C"
import "github.com/fatih/color"
//export Hello
func Hello() {
color.Green("Hello, 世界")
}
func main() {}
from cffi import FFI
ffibuilder = FFI()
ffibuilder.set_source("_hello", """
#include "hello.h"
""", extra_objects=["hello.a"])
ffibuilder.cdef("void Hello();")
if __name__ == "__main__":
ffibuilder.compile(verbose=True)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment