Hello.
I would like bind C library to Rust.
errors:
undefined reference to lib's functions
Project tree:
├── build.rs
├── Cargo.toml
├── README
└── src
├── API.rs
└── main.rs
Cargo.toml:
[package]
name = "my_lib"
version = "0.1.0"
authors = ["JPE"]
edition = "2018"
build = "build.rs"
[lib] # Bindings
name = "my_lib"
path = "src/API.rs"
[[bin]] # Bin with Examples
name = "my_lib_rust_example"
path = "src/main.rs"
[dependencies]
libc = "0.2.71"
build.rs:
use std::env;
fn main()
{
let dst = env::var("PWD").unwrap();
println!("cargo:rustc-link-search=native={}/../", dst);
println!("cargo:include={}/../../include", dst);
println!("cargo:rustc-flags=-l dylib=stdc++"); //link c++ std library when using gcc
}