Closed
Description
Using --target feature in rust will hard-code the provided path in the library. Linking these libraries against applications will fail if they use same target.json but with a different (e.g., relative) path.
I tried this code:
lib.rs:
#![feature(no_std)]
#![no_std]
main.rs
#![feature(lang_items, start, no_std)]
#![no_std]
extern crate lib;
#[lang="phantom_fn"]
trait PhantomFn<A: ?Sized, R: ?Sized = ()> {}
#[lang="sized"]
trait Sized: PhantomFn<Self> {}
#[lang="copy"]
trait Copy: PhantomFn<Self> {}
#[lang="sync"]
trait Sync: PhantomFn<Self> {}
#[start]
fn start() {
}
#[lang = "stack_exhausted"] extern fn stack_exhausted() {}
#[lang = "eh_personality"] extern fn eh_personality() {}
#[lang = "panic_fmt"] fn panic_fmt() -> ! { loop {} }
Now, I compile the lib.rs as a library
rustc --crate-type=lib --emit=link -O --cfg arch__x86_64 --target=target.json --crate-name lib lib.rs
...and main.rs as an application using liblib.rlib (I'm in folder play):
Works:
rustc --emit=obj -L dependency=./ -O --cfg arch__x86_64 --target=target.json --extern lib=./liblib.rlib -o main.o main.rs
Does not work:
rustc --emit=obj -L dependency=./ -O --cfg arch__x86_64 --target=../play/target.json --extern lib=./liblib.rlib -o main.o main.rs
Instead, this happened:
rustc --emit=obj -L dependency=./ -O --cfg arch__x86_64 --target=../play/target.json --extern lib=./liblib.rlib -o main.o main.rs
main.rs:4:1: 4:18 error: couldn't find crate `lib` with expected target triple ../play/target.json
main.rs:4 extern crate lib;
^~~~~~~~~~~~~~~~~
main.rs:4:18: 4:18 note: crate `lib`, path #1, triple target.json: /home/gz/workspace/play/liblib.rlib
error: aborting due to previous error
Meta
rustc --version --verbose
:
rustc 1.0.0-nightly (c89de2c56 2015-03-28) (built 2015-03-29)
binary: rustc
commit-hash: c89de2c56baeb61e7cc434924dcc8bedd32b26b8
commit-date: 2015-03-28
build-date: 2015-03-29
host: x86_64-unknown-linux-gnu
release: 1.0.0-nightly