Skip to content
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

Multiple definitions #1693

Closed
TomzBench opened this issue Dec 12, 2019 · 3 comments
Closed

Multiple definitions #1693

TomzBench opened this issue Dec 12, 2019 · 3 comments

Comments

@TomzBench
Copy link

TomzBench commented Dec 12, 2019

I have a really rough looking header (it's amalgamation).

https://github.com/TomzBench/mongoose-rs/blob/master/mongoose-sys/wrapper.h

Mongoose is a pretty popular single threaded web server for embedded systems written in C. So I went to try and make a binding to it and when I compile it I get a few errors such as seen below. (My repository is pretty minimal to reproduce.)

1007 | pub const IPPORT_RESERVED: u32 = 1024;
     | -------------------------------------- previous definition of the value `IPPORT_RESERVED` here
...
3092 | pub const IPPORT_RESERVED: _bindgen_ty_6 = 1024;
     | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ `IPPORT_RESERVED` redefined here
975  | pub const FP_NAN: u32 = 0;
     | -------------------------- previous definition of the value `FP_NAN` here
...
5166 | pub const FP_NAN: _bindgen_ty_8 = 0;
     | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ `FP_NAN` redefined here

The culprit is defined first as:

pub const FP_NAN: u32 = 0;
pub const FP_INFINTE: u32 = 1;
pub const FP_ZERO: u32 = 2;
pub const FP_NORMAL: u32 = 3;

Then it is redefined again some 5000 lines later as

pub const FP_NAN: __bindgen_ty_8 = 0;
pub const FP_INFINTE: __bindgen_ty_8 = 1;
pub const FP_ZERO: __bindgen_ty_8 = 2;
pub const FP_NORMAL: __bindgen_ty_8 = 3;

It looks like __bindgen_ty_8 is a u32 so they are defined as equal - but still produces error.
(also If I copy out the binding.rs and delete the duplicate's then it does compile ok...)

@emilio
Copy link
Contributor

emilio commented Dec 12, 2019

How are these defined in your system? Your header doesn't include those constants...

This looks like a dupe of #687, where we have both a macro and an anonymous enum with the same name.

Bindgen can't quite now what to generate and generates both. You can instruct bindgen to generate the variant you want as described in that issue.

@emilio emilio closed this as completed Dec 12, 2019
@TomzBench
Copy link
Author

...I thought because those constants were not part of the header, that bindgen added them for some reason. Since the header does not contain FP_* symbols, it is hard to figure out what the header is defining twice. I think the header is indirectly tricking bindgen into defining FP_* twice.

@emilio
Copy link
Contributor

emilio commented Dec 13, 2019

Bindgen generates everything by default, you need to whitelist (which is recursive by default) or blacklist stuff to limit the output.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants