Skip to content

extern mod inside of module doesn't work as expected #4677

Closed

Description

@jbclements

It doesn't seem possible to use 'extern mod' inside of a module.

in file cratey.rs:

#[ link(name = "cratey",
        vers = "0.1",
        uuid = "418CE8FB-DE11-4FEF-BC71-E3F36047696F") ];

#[ crate_type = "lib" ];

pub fn add1 (x : int) -> int { x + 1 }

In the same directory, crateuser.rs:

pub mod mymod {
  extern mod cratey;
  use cratey::add1;
  fn main() { add1(3); }
}

compilation of the crate works fine, but linking against it causes an error:

machine> rustc cratey.rs
Running /Users/clements/rust/build/x86_64-apple-darwin/stage2/bin/rustc:
warning: no debug symbols in executable (-arch x86_64)
machine> rustc -L . crateuser.rs
Running /Users/clements/rust/build/x86_64-apple-darwin/stage2/bin/rustc:
crateuser.rs:6:4: 6:17 error: unresolved name
crateuser.rs:6 use cratey::add1;
                   ^~~~~~~~~~~~~
crateuser.rs:6:4: 6:17 error: failed to resolve import: cratey::add1
crateuser.rs:6 use cratey::add1;
                   ^~~~~~~~~~~~~
error: failed to resolve imports
error: aborting due to 3 previous errors

Removing the "mod mymod" wrapper allows the thing to compile fine. Apologies if this is the way it's supposed to work; casual stand-up-and-shout suggests to me that it should be possible to put an extern mod inside a module.

Activity

  1. graydon commented on Jan 30, 2013

    @graydon
    Contributor

    Use self::cratey::add1 ?

  2. jbclements commented on Jan 30, 2013

    @jbclements
    ContributorAuthor

    I see... 'use' paths are relative to the crate root, and not to the current module. I've added a note (not yet pushed) to the documentation about this; hopefully this will prevent others from making this mistake.

    Thanks!

    Closing this issue.

  3. added a commit that references this issue on Oct 9, 2020
    019c0d5
  4. added a commit that references this issue on Nov 11, 2025
  5. added a commit that references this issue on Dec 10, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions