<p dir="auto">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.</p>
<p dir="auto">I tried this code:<br>
lib.rs:</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="#![feature(no_std)]
#![no_std]"><pre class="notranslate"><code class="notranslate">#![feature(no_std)]
#![no_std]
</code></pre></div>
<p dir="auto">main.rs</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="#![feature(lang_items, start, no_std)]
#![no_std]
extern crate lib;

#[lang=&quot;phantom_fn&quot;]
trait PhantomFn&lt;A: ?Sized, R: ?Sized = ()&gt; {}
#[lang=&quot;sized&quot;]
trait Sized: PhantomFn&lt;Self&gt; {}
#[lang=&quot;copy&quot;]
trait Copy: PhantomFn&lt;Self&gt; {}
#[lang=&quot;sync&quot;]
trait Sync: PhantomFn&lt;Self&gt; {}

#[start]
fn start() {
}
#[lang = &quot;stack_exhausted&quot;] extern fn stack_exhausted() {}
#[lang = &quot;eh_personality&quot;] extern fn eh_personality() {}
#[lang = &quot;panic_fmt&quot;] fn panic_fmt() -&gt; ! { loop {} }"><pre class="notranslate"><code class="notranslate">#![feature(lang_items, start, no_std)]
#![no_std]
extern crate lib;

#[lang="phantom_fn"]
trait PhantomFn&lt;A: ?Sized, R: ?Sized = ()&gt; {}
#[lang="sized"]
trait Sized: PhantomFn&lt;Self&gt; {}
#[lang="copy"]
trait Copy: PhantomFn&lt;Self&gt; {}
#[lang="sync"]
trait Sync: PhantomFn&lt;Self&gt; {}

#[start]
fn start() {
}
#[lang = "stack_exhausted"] extern fn stack_exhausted() {}
#[lang = "eh_personality"] extern fn eh_personality() {}
#[lang = "panic_fmt"] fn panic_fmt() -&gt; ! { loop {} }
</code></pre></div>
<p dir="auto">Now, I compile the lib.rs as a library</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="rustc --crate-type=lib --emit=link -O --cfg arch__x86_64 --target=target.json --crate-name lib lib.rs"><pre class="notranslate"><code class="notranslate">rustc --crate-type=lib --emit=link -O --cfg arch__x86_64 --target=target.json --crate-name lib lib.rs
</code></pre></div>
<p dir="auto">...and main.rs as an application using liblib.rlib (I'm in folder play):</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="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"><pre class="notranslate"><code class="notranslate">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
</code></pre></div>
<p dir="auto">Instead, this happened:</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="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"><pre class="notranslate"><code class="notranslate">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
</code></pre></div>
<h2 dir="auto">Meta</h2>
<p dir="auto"><code class="notranslate">rustc --version --verbose</code>:</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="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"><pre class="notranslate"><code class="notranslate">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
</code></pre></div>
<p dir="auto">the ./configure output is :</p>
<p dir="auto">configure: looking for configure programs<br>
configure: found program cmp<br>
configure: found program mkdir<br>
configure: found program printf<br>
configure: found program cut<br>
configure: found program head<br>
configure: found program grep<br>
configure: found program xargs<br>
configure: found program cp<br>
configure: found program find<br>
configure: found program uname<br>
configure: found program date<br>
configure: found program tr<br>
configure: found program sed<br>
configure: found program file<br>
configure: found program make<br>
configure: inspecting environment<br>
configure: recreating config.tmp<br>
configure:<br>
configure: processing ./configure args<br>
configure:<br>
configure: CFG_LOCALSTATEDIR    := /var/lib<br>
configure: CFG_SYSCONFDIR       := /etc<br>
configure: CFG_DATADIR          := /share<br>
configure: CFG_INFODIR          := /share/info<br>
configure: CFG_LLVM_ROOT        :=<br>
configure: CFG_JEMALLOC_ROOT    :=<br>
configure: CFG_BUILD            := x86_64-apple-darwin<br>
configure: CFG_ANDROID_CROSS_PATH := /opt/ndk_standalone<br>
configure: CFG_RELEASE_CHANNEL  := dev<br>
configure: CFG_MUSL_ROOT        := /usr/local<br>
configure: CFG_BUILD            := x86_64-apple-darwin<br>
configure: CFG_LIBDIR           := /usr/local/lib<br>
configure:<br>
configure: validating ./configure args<br>
configure:<br>
configure: CFG_BOOTSTRAP_KEY    := 21:11:31<br>
configure:<br>
configure: looking for build programs<br>
configure:<br>
configure: CFG_CURLORWGET       := /usr/bin/curl (7.37.1)<br>
configure: CFG_PYTHON           := /usr/bin/python2.7<br>
configure: CFG_GIT              := /usr/bin/git (2.3.8)<br>
configure: git: no git directory. disabling submodules<br>
configure: CFG_MD5              := /sbin/md5<br>
configure: CFG_MD5SUM           :=<br>
configure: CFG_HASH_COMMAND     := /sbin/md5 -q | head -c 8<br>
configure: CFG_CLANG            := /usr/bin/clang++ (7.0.0)<br>
configure: CFG_CCACHE           :=<br>
configure: CFG_GCC              := /usr/bin/gcc (7.0.0)<br>
configure: CFG_LD               := /usr/bin/ld<br>
configure: CFG_VALGRIND         :=<br>
configure: CFG_PERF             :=<br>
configure: CFG_ISCC             :=<br>
configure: CFG_ANTLR4           :=<br>
configure: CFG_GRUN             :=<br>
configure: CFG_FLEX             := /usr/bin/flex (2.5.35)<br>
configure: CFG_BISON            := /usr/bin/bison (2.3)<br>
configure: CFG_PANDOC           :=<br>
configure: CFG_XELATEX          :=<br>
configure: CFG_GDB              :=<br>
configure: CFG_LLDB             := /usr/bin/lldb (340.4.53.3)<br>
configure: CFG_DISABLE_VALGRIND_RPASS := 1<br>
configure: CFG_LLDB_VERSION     := lldb-340.4.53.3<br>
configure: CFG_LLDB_PYTHON_DIR  := /Library/Developer/CommandLineTools ...<br>
configure:<br>
configure: looking for target specific programs<br>
configure:<br>
configure: CFG_ADB              :=<br>
configure:<br>
configure: on OS X &gt;=10.9, forcing use of clang<br>
configure:<br>
configure: CFG_ENABLE_CLANG     := 1<br>
configure: CFG_USING_CLANG      := 1<br>
configure: error: bad CLANG version: 7.0.0, need &gt;=3.0svn</p>