Rust + Golang
make build and then
./main to see
Golang in action. You
Hello John Smith! printed to
You can do this for your own project
Begin by creating a
lib directory, where you will keep your Rust libraries.
Andrew Oppenlander's article on creating a Rust dynamic library is a great introduction.
Then, you need to create a C header file for your library. Just copy the
types that you used.
All that is left to do is to add some
cgo-specific comments to your Golang
code. These comments tell
cgo where to find the library and its headers.
/* #cgo LDFLAGS: -L./lib -lhello #include "./lib/hello.h" */ import "C"
There should not be a newline between
make build (use the Makefile in this repository) will
result in a binary that loads your dynamic library.