-
Notifications
You must be signed in to change notification settings - Fork 742
the name <> is defined multiple times caused by enum and integer definition #2008
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
That C code complains here:
I wonder why they didn't use the more common and portable:
Anyhow bindgen could probably be taught about this pattern. |
@emilio This is also the solution I went with now. Changing the C code to only declare it once. Here is a thread with the author of the code code explaining the current implementation. https://chat.spectre.app/d/6-issue-compiling-the-spectre-api/7 From my side the issue is solved. It still would be great if bindgen handles this out of the box. Should I keep the issue open? |
This is a common idiom in C. $ cbindgen --lang c <(echo '
#[repr(i16)]
pub enum Asdf { Jkl }
#[no_mangle]
pub extern "C" fn f(asdf: Asdf) {}
')
#include <stdarg.h>
#include <stdbool.h>
#include <stdint.h>
#include <stdlib.h>
enum Asdf {
Jkl,
};
typedef int16_t Asdf;
void f(Asdf asdf); @emilio if you were seeing a "conflicts with typedef" error, it's because you must have been using a C++ compiler. This code is valid and idiomatic in C. |
Fixes rust-lang#2008. Example: ```c enum Enum { Variant }; typedef int16_t Enum; ``` This is valid and idiomatic C (though not valid C++). `cbindgen` uses this idiom as the default C translation of Rust enums, the equivalent of what would be `enum Enum : int16_t { Variant };` in C++. `bindgen header.h` before: ```rust pub const Enum_Variant: Enum = 0; pub type Enum = ::std::os::raw::c_uint; pub type Enum = i16; ``` ```console error[E0428]: the name `Enum` is defined multiple times --> generated.rs:3:1 | 2 | pub type Enum = ::std::os::raw::c_uint; | --------------------------------------- previous definition of the type `Enum` here 3 | pub type Enum = i16; | ^^^^^^^^^^^^^^^^^^^^ `Enum` redefined here | = note: `Enum` must be defined only once in the type namespace of this module ``` After: ```rust pub const Enum_Variant: Enum = 0; pub type Enum = i16; ```
Input C/C++ Header
Bindgen Invocation
Builder command:
Actual Results
Produced bindings.rs
Error from cargo:
Expected Results
The bindgen should just irgnore the duplicate definition of the
SpectreAlgorithm
type. In c the enum and the integer are used for easier function signatures.The text was updated successfully, but these errors were encountered: