1

我尝试使用bindgen自动生成 Rust FFI 绑定到 C 和 C++ 库,用于 Oracle 数据库的 OCI 绑定。

我遵循bindgen用户指南,我这样做了:

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 系统上执行此操作。

4

0 回答 0