Import Go from Python the "right" way
This file contains 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
go build -buildmode=c-archive . | |
python hello_build.py | |
python -c "import _hello; _hello.lib.Hello()" |
This file contains 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 "github.com/fatih/color" | |
//export Hello | |
func Hello() { | |
color.Green("Hello, 世界") | |
} | |
func main() {} |
This file contains 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
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