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

extern crate not quite the same as --extern #73531

Closed
adetaylor opened this issue Jun 20, 2020 · 2 comments
Closed

extern crate not quite the same as --extern #73531

adetaylor opened this issue Jun 20, 2020 · 2 comments

Comments

@adetaylor
Copy link
Contributor

The documentation for the --extern rustc command line flag seems to suggest it's functionally identical to extern crate.

Specifically:

The given crate name is added to the extern prelude, which is the same as specifying extern crate within the root module.

However, if there are #[no_mangle] symbols in the crate, then consumed into a staticlib there's a difference. I don't know if this is intentional, and/or whether I'm misinterpreting the documentation, so I'm raising an issue to ask rather than filing a PR against the documentation.

Test case here

Do this:

  1. cd client
  2. ./build-a.sh. This uses extern crate rlib; and should successfully build a C executable including a Rust symbol.
  3. ./build-b.sh. This uses --extern and instead reports:
Undefined symbols for architecture x86_64:
  "_do_some_maths", referenced from:
      _main in test-2e4db9.o
ld: symbol(s) not found for architecture x86_64

rustc 1.45.0-nightly (a08c47310 2020-05-07)

@tmiasko
Copy link
Contributor

tmiasko commented Jun 20, 2020

Related issues #64731, #64402.

@adetaylor
Copy link
Contributor Author

Ah great, thanks. I regard this as a duplicate of #64731. I may come up with a documentation PR.

adetaylor added a commit to adetaylor/rust that referenced this issue Jun 21, 2020
Manishearth added a commit to Manishearth/rust that referenced this issue Jun 23, 2020
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