Bindgen: the name `std_size_type` is defined multiple times

I’m still trying to prove that Rust can interface with our internal SDK and I manage to succeed on the C part. But some of the SDK is written in C++ and I’m trying to generate FFI with bindgen.

binding.rs is generated ok but I have this issue:

error[E0428]: the name `std_size_type` is defined multiple times
      --> C:\Users\Geobomatic\Documents\CODE\rust\driver-primitives-sys\target\debug\build\driver-primitives-sys-7706057f8b57b49f\out/bindings.rs:228783:1
       |
228782 | pub type std_size_type = size_type;
       | ----------------------------------- previous definition of the type `std_size_type` here
228783 | pub type std_size_type = size_type;
       | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ `std_size_type` redefined here
       |
       = note: `std_size_type` must be defined only once in the type namespace of this module

I tried to opaque std::*:

 bindgen::Builder::default()
    .header("wrapper.h")
    .clang_arg("-I../PlatformSDK/CommonUtilities/Include")
    .clang_arg("-x")
    .clang_arg("c++")
    .clang_arg("-std=c++14")
    .opaque_type("std::*")
    .opaque_type("size_type")
    .generate()
    .expect("Unable to generate bindings");

but I still got the error.

Did any body succeed generating a compilable bindings.rs from C++?
Otherwise I’ll copy paste bindings.rs and fix it manually but I’d rather have an automated build.

I have similar issues with with chuck-sys. I’m using sed regex to comment the troublesome lines, ugly hack to get it to generate and compile on the fly. I’m still experimenting with scripting the build process and different flags. The library is still a ways away from 1.0, so it’s a process.

I ended writing a C wrapper around the C++ code

1 Like

That seems to be a popular solution, cimgui does the same thing. I’ll have to study it more closely

Having a C wrapper makes all ffi easier, not just rust.