Skip to content

rustc: -L also indicates the location of native libraries #2197

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

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions src/rustc/back/link.rs
Original file line number Diff line number Diff line change
Expand Up @@ -580,6 +580,8 @@ fn link_binary(sess: session,
lib_cmd = "-dynamiclib";
} else { lib_cmd = "-shared"; }

// # Crate linking

let cstore = sess.cstore;
for cstore::get_used_crate_files(cstore).each {|cratepath|
if str::ends_with(cratepath, ".rlib") {
Expand All @@ -596,6 +598,18 @@ fn link_binary(sess: session,
let ula = cstore::get_used_link_args(cstore);
for ula.each {|arg| cc_args += [arg]; }

// # Native library linking

// User-supplied library search paths (-L on the cammand line) These are
// the same paths used to find Rust crates, so some of them may have been
// added already by the previous crate linking code. This only allows them
// to be found at compile time so it is still entirely up to outside
// forces to make sure that library can be found at runtime.

let addl_paths = sess.opts.addl_lib_search_paths;
for addl_paths.each {|path| cc_args += ["-L" + path]; }

// The names of the native libraries
let used_libs = cstore::get_used_libraries(cstore);
for used_libs.each {|l| cc_args += ["-l" + l]; }

Expand Down Expand Up @@ -639,6 +653,8 @@ fn link_binary(sess: session,
// Stack growth requires statically linking a __morestack function
cc_args += ["-lmorestack"];

// FIXME: At some point we want to rpath our guesses as to where
// native libraries might live, based on the addl_lib_search_paths
cc_args += rpath::get_rpath_flags(sess, output);

#debug("%s link args: %s", cc_prog, str::connect(cc_args, " "));
Expand Down
14 changes: 14 additions & 0 deletions src/test/run-pass/native-lib-path.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
// xfail-test FIXME I don't know how to test this
// compile-flags:-L.
// The -L flag is also used for linking native libraries

// FIXME: I want to name a mod that would not link successfully
// wouthout providing a -L argument to the compiler, and that
// will also be found successfully at runtime.
native mod WHATGOESHERE {
fn IDONTKNOW() -> u32;
}

fn main() {
assert IDONTKNOW() == 0x_BAD_DOOD_u32;
}