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

The link options are ignored. #104

Closed
emilio opened this issue Oct 19, 2016 · 14 comments
Closed

The link options are ignored. #104

emilio opened this issue Oct 19, 2016 · 14 comments

Comments

@emilio
Copy link
Contributor

emilio commented Oct 19, 2016

It seems that I dropped them during the rewrite, can't remember if I did it accidentally or not.

In any case, we announce to support it and don't, which should be fixed either removing the option or supporting it properly.

@jdub
Copy link
Contributor

jdub commented Nov 4, 2016

What should they do? Detect if its running in build.rs and print cargo:rustc-link-lib= lines? Add #[link] attributes?

@emilio
Copy link
Contributor Author

emilio commented Nov 4, 2016

The old behavior for this option is to create #[link] attributes. I'm still pretty dubious it's the right functionality to have builtin support for in bindgen, but some people seemed to disagree on IRC and found it useful.

@metajack
Copy link
Contributor

metajack commented Nov 4, 2016

This is probably a good thing to ask @alexcrichton

@alexcrichton
Copy link
Member

rustc-link-lib and #[link] are equivalent, so it shouldn't matter which is used

@metajack
Copy link
Contributor

metajack commented Nov 4, 2016

I think in the past we've preferred rustc-link-lib because having this information outside of build.rs made a mess.

@jdub
Copy link
Contributor

jdub commented Nov 4, 2016

OK, for now I'll spit out rustc-link-lib directives if we're in build.rs, and otherwise continue to ignore the link flags.

I'll fix this with my docopt changes in #202.

@jdub
Copy link
Contributor

jdub commented Nov 4, 2016

Hmm, I might hold off and do it separately. It's unclear when it should happen in the library use case: On generate() or write()? Probably write(), but your feedback would be appreciated.

@jsgf
Copy link
Contributor

jsgf commented Jan 4, 2017

I was expecting these options to add #[link] to the extern block. I'm currently faking this with --raw-line=#[link(name = "mylib++")] extern {} which seems OK, but I'm concerned that a future version of the compiler would treat the extern {} as useless and drop it - I'd feel more comfortable if it were attached to an extern block with signatures in it.

build.rs-based approaches aren't useful for me because I'm not using cargo to build.

@ryankurte
Copy link

ryankurte commented Feb 13, 2017

Updating stuff from a previous bindgen / rust version, and also not using cargo to build. Is there a recommended solution for this?
Current approach is sed -i '' 's/^extern "C" {/#[link(name = "${LIBNAME}")] extern "C" {/' ${FILENAME} after generation, in case that is useful to others.

@emilio
Copy link
Contributor Author

emilio commented Feb 13, 2017

@ryankurte I believe the cleanest solution for this is --raw-line for now. I don't have the time right now to implement this, but I'm happy to mentor anyone wanting to do so.

@ryankurte
Copy link

ryankurte commented Feb 13, 2017 via email

@mitchmindtree
Copy link

mitchmindtree commented Jan 26, 2018

I've just run into this issue when generating new bindings using the CLI (and regenerating old bindings) for the coreaudio-sys crate, specifically when linking the necessary frameworks (CoreAudio, AudioUnit, AudioToolbox, etc).

The generated link_name for each function (e.g. #[link_name = "\u{1}__Z21AudioUnitUninitialize"]) results in "undefined symbols for platform" when depending on coreaudio-sys from another crate.

However if I remove the link_name above each generated function and add #[link(name = "AudioUnit", kind = "framework")] above the enclosing extern "C" block that is around each function, it works successfully.

I'm unsure how to work around this in the meantime as there's a few thousand of these blocks in each module, and although I could test a few individual functions successfully my sed/grep find and replace skills are not quite up to this task of handling every function properly.

Any tips on how to either work around this or fix this in rust-bindgen itself would be greatly appreciated!

@mitchmindtree
Copy link

FWIW I'm getting the same issue even when generating the bindings using a build.rs script - see the build script on the branch here. Perhaps i'm incorrectly linking the frameworks here?

@mitchmindtree
Copy link

Ah, disabling trust_clang_mangling seems to fix linking with the build.rs-generated approach.

emilio added a commit to emilio/rust-bindgen that referenced this issue Mar 31, 2018
They do nothing, and are effectively superseded by --raw-line and friends.

They also tend to confuse people.

Closes rust-lang#104
bors-servo pushed a commit that referenced this issue Apr 2, 2018
options: Remove the linking-related options.

They do nothing, and are effectively superseded by --raw-line and friends.

They also tend to confuse people.

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

No branches or pull requests

8 participants