我尝试使用bindgen
自动生成针对Oracle数据库的OCI绑定的C和C ++库的Rust FFI绑定。
我跟着the bindgen
User Guide,我这样做了:
extern crate bindgen;
use std::env;
use std::path::PathBuf;
fn main() {
println!("cargo:rustc-link-search={}", "E:\\Rust\\instantclient_11_2\\sdk\\lib\\msvc");
let bindings = bindgen::Builder::default()
.header("wrapper.h")
.clang_arg("-I/E:\\Rust\\instantclient_11_2\\sdk\\include")
.generate()
.expect("Unable to generate to bindings");
let out_path = PathBuf::from(env::var("OUT_DIR").unwrap());
bindings.write_to_file(out_path.join("oci.rs"))
.expect("Couldn't write bindings");
}
我的Oracle客户端SDK路径为E:/Rust/instantclient_11_2
,活动工具链为nightly-x86_64-pc-windows-msvc
wrapper.h
文件为:
#include <oci.h>
当我运行cargo build
时,我收到以下错误:
Compiling test_bindgen v0.1.0 (file:///E:/Rust/test_bindgen)
error: failed to run custom build command for `test_bindgen v0.1.0 (file:///E:/Rust/test_bindgen)`
process didn't exit successfully: `E:\Rust\test_bindgen\target\debug\build\test_bindgen-67bec61306f8f8d4\build-script-build` (ex
it code: 101)
--- stdout
cargo:rustc-link-search=E:\Rust\instantclient_11_2\sdk\lib\msvc
wrapper.h:1:10: fatal error: 'oci.h' file not found, err: true
--- stderr
wrapper.h:1:10: fatal error: 'oci.h' file not found
thread 'main' panicked at 'Unable to generate to bindings: ()', src\libcore\result.rs:906:4
note: Run with `RUST_BACKTRACE=1` for a backtrace.
如果我在Ubuntu 16.04上执行相同的操作,它会成功,但我不知道如何在Windows系统上执行此操作。