1

I tried to use bindgen to automatically generate Rust FFI bindings to C and C++ libraries for the OCI bindings for an Oracle database.

I followed the bindgen User Guide, and I did it like this:

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");
}

My Oracle client SDK path is E:/Rust/instantclient_11_2, and the active toolchain is nightly-x86_64-pc-windows-msvc The wrapper.h file is:

#include <oci.h>

When I run cargo build, I get the following error:

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.

If I perform the same operation on Ubuntu 16.04 it succeeds, but I don't know how to do it on a Windows system.

Shepmaster
  • 388,571
  • 95
  • 1,107
  • 1,366
yelan_fn
  • 41
  • 1
  • 3
  • 1
    Why do you need a `/` between `-I` and `E:` in `.clang_arg()`? – kennytm Aug 29 '17 at 07:17
  • Oh, I am really too foolish. I took it for granted that this was the case: there should be someing(maybe a space,or a /) between -I and E:/. I think i should look at the help document of clang. Thanks a lot!! – yelan_fn Aug 30 '17 at 00:47

0 Answers0