diff options
| author | Brian Anderson <banderson@mozilla.com> | 2012-04-13 21:38:15 -0700 |
|---|---|---|
| committer | Brian Anderson <banderson@mozilla.com> | 2012-04-16 12:33:21 -0700 |
| commit | f466a2fa8f7594d6895bb4263a662adc7ed26326 (patch) | |
| tree | 89ae6b80fa20d1fda0afa8b108969aa52f0eda51 /src/rustc | |
| parent | 903cb0e3a5273f68c5c27dbfbfbe2e4c6721bd37 (diff) | |
| download | rust-f466a2fa8f7594d6895bb4263a662adc7ed26326.tar.gz rust-f466a2fa8f7594d6895bb4263a662adc7ed26326.zip | |
rustc: -L also indicates the location of native libraries
-L currently specifies paths to search for Rust crates
Building crates that use native libraries is difficult. When the
library is located somewhere unexpected there is no way
to tell rustc additional paths to look in.
If libclang is located at `.` then rustc is not going to
know that and linking will fail.
To get around that I often end up inserting
#[link_args = "-L."] native mod m { }
into other crates to get them to build.
Now you just `rustc -L .` and it builds.
This doesn't do any rpathing so it's still up to somebody else
to put the library somewhere it will be found or use LD_LIBRARY_PATH
This feature comes with a single, XFAILed test, because I could
not think of a way to test it. Odd.
Diffstat (limited to 'src/rustc')
| -rw-r--r-- | src/rustc/back/link.rs | 16 |
1 files changed, 16 insertions, 0 deletions
diff --git a/src/rustc/back/link.rs b/src/rustc/back/link.rs index 11c3f43f666..8bf6c585557 100644 --- a/src/rustc/back/link.rs +++ b/src/rustc/back/link.rs @@ -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") { @@ -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]; } @@ -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, " ")); |
