Skip to content

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

@adetaylor

Description

@adetaylor

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)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions