This project implements a simple FFI call of Rust library in Go:
The Rust project is compiled as a static library The Go project embeds the Rust library and accesses it with CGO
Step 1: Install Golang
- Install a correctly configured Go toolchain (version 1.21+).
- Make sure that your
GOPATH
andGOBIN
environment variables are properly set up.
Step 2: Install Rust
- Install a correctly configured Rust toolchain (version 1.58.0+).
# Download sources from github
git clone https://github.com/oligami-0424/ffi-rust-go
# Go to sources directory
cd ffi-rust-go
# Build
cargo build
# Run
cargo run
## Build and run Docker container:
```bash
# Build Docker image
docker build -t ffi-rust-go .
# Run Docker container
docker run -it ffi-rust-go /bin/ash
/# ffi-rust-go
:print on rust
Segmentation fault
We have confirmed that it works fine in WSL (Ubuntu), but it does not work well in other operating systems.
on all Complete program!
Go into a Go function and cause a Segmentation fault.
The moment I call a Go function, it freezes.
error: linking with link.exe
failed: exit code: 1120
libstd-d9ee307034db292c.rlib(std-d9ee307034db292c.std.e9da0a539f4e1ec4-cgu.0.rcgu.o) : warning LNK4078: multiple '.drectve' sections found with different attributes (00100A00)
libffi_go_print.lib(000005.o) : error LNK2019: unresolved external symbol fprintf referenced in function _cgo_beginthread
C:\Users\oligami\ffi-rust-go\target\debug\deps\ffi_rust_go.exe : fatal error LNK1120: 1 unresolved externals
Your confirmation on the OS and input is welcome!
compile tool is gcc (Strawberry)
- |success| c lang call static golang
- |success| c lang call static c lang
- |success| rust lang call static c lang
- |failed | rust lang call static go lang