https://github.com/anzhi0708/example-rust-c-ffi
Minimal example for calling C function from Rust code
https://github.com/anzhi0708/example-rust-c-ffi
build build-system c cargo clang example examples examples-rust ffi foreign-function-interface rust std stdlib
Last synced: 8 days ago
JSON representation
Minimal example for calling C function from Rust code
- Host: GitHub
- URL: https://github.com/anzhi0708/example-rust-c-ffi
- Owner: anzhi0708
- Created: 2025-02-09T14:56:07.000Z (over 1 year ago)
- Default Branch: main
- Last Pushed: 2025-04-19T12:04:42.000Z (about 1 year ago)
- Last Synced: 2025-10-25T16:56:15.645Z (7 months ago)
- Topics: build, build-system, c, cargo, clang, example, examples, examples-rust, ffi, foreign-function-interface, rust, std, stdlib
- Language: Shell
- Homepage:
- Size: 4.88 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Minimal Rust C FFI example
## Keypoints
- Add `build = "src/build.rs"` in `Cargo.toml` (otherwise cargo sometimes fails to pick it up and I don't know why)
- `#[link(name = "hello", kind = "dylib")]` (or another kind; in this case a dylib)
- `cargo:rustc-link-search` flag in `build.rs` file
- Set environment variables correctly (Linux: `LD_LIBRARY_PATH`, Mac: `DYLD_LIBRARY_PATH`)
`build_and_run` bash script sets enviroment variables for you; you may want to take a look at it.