Simple examples showing how to embed Julia in Go.
Julia, Go, Make.
go
, julia
and julia-config.jl
in your path.
You will probably have to add julia-config.jl
to your PATH. Julia config tool on macOS, using Julia installed with brew is located here:
/Applications/Julia-1.2.app/Contents/Resources/julia/share/julia/julia-config.jl
This was tested on macOS, but should also work on Linux.
A makefile is provide for convenience, just type:
make
This will compile the examples and run them (note: one of the example will fail on purpose).
There are 3 examples:
gjl.go
: very simple examplegjl_goroutines.go
: executing julia code from 2 different goroutines with synchronisation.gjl_goroutines_fail.go
: same as above example, but demonstrate failure when accessing julia from multiple goroutine without synchronization.
Julia is embedding in Go using cgo and a couple of C binding files: gjl.h
and gjl.c
.
These files provide function wrappers around Julia C API that are defined C macros in Julia. Cgo cannot use C macros directly. For example jl_typeof(v) is a macro.