<p dir="auto">Building <a href="https://github.com/ogham/exa">exa</a> fails at link stage if LTO is used and system package for libssh2-dev is not installed:</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="Compiling exa v0.3.0 (file:///home/butler/packs/exa)
error: linking with `cc` failed: exit code: 1
note: &quot;cc&quot; &quot;-Wl,--as-needed&quot; &quot;-m64&quot; &quot;-L&quot; &quot;/home/butler/.multirust/toolchains/nightly/lib/rustlib/x86_64-unknown-linux-gnu/lib&quot; &quot;/home/butler/packs/exa/target/release/exa.0.o&quot; &quot;-o&quot; &quot;/home/butler/packs/exa/target/release/exa&quot; &quot;-Wl,--gc-sections&quot; &quot;-pie&quot; &quot;-Wl,-O1&quot; &quot;-nodefaultlibs&quot; &quot;-Wl,--whole-archive&quot; &quot;/tmp/rustc.0qWCH5Q46Uym/liblibgit2_sys-92cc88eed912bce1.rlib&quot; &quot;-Wl,--no-whole-archive&quot; &quot;-Wl,--whole-archive&quot; &quot;/tmp/rustc.0qWCH5Q46Uym/liblibssh2_sys-63d236645b9d2140.rlib&quot; &quot;-Wl,--no-whole-archive&quot; &quot;-Wl,--whole-archive&quot; &quot;/tmp/rustc.0qWCH5Q46Uym/libopenssl_sys-e0bd245bf09b1a3f.rlib&quot; &quot;-Wl,--no-whole-archive&quot; &quot;-Wl,--whole-archive&quot; &quot;/tmp/rustc.0qWCH5Q46Uym/libstd-35017696.rlib&quot; &quot;-Wl,--no-whole-archive&quot; &quot;-Wl,--whole-archive&quot; &quot;/tmp/rustc.0qWCH5Q46Uym/liballoc_jemalloc-35017696.rlib&quot; &quot;-Wl,--no-whole-archive&quot; &quot;-L&quot; &quot;/home/butler/packs/exa/target/release&quot; &quot;-L&quot; &quot;/home/butler/packs/exa/target/release/deps&quot; &quot;-L&quot; &quot;/home/butler/packs/exa/target/release/build/libgit2-sys-92cc88eed912bce1/out/lib&quot; &quot;-L&quot; &quot;/home/butler/packs/exa/target/release/build/libssh2-sys-63d236645b9d2140/out/lib&quot; &quot;-L&quot; &quot;/usr/lib/x86_64-linux-gnu&quot; &quot;-L&quot; &quot;/home/butler/packs/exa/target/release/build/libssh2-sys-63d236645b9d2140/out/lib&quot; &quot;-L&quot; &quot;/usr/lib/x86_64-linux-gnu&quot; &quot;-L&quot; &quot;/usr/lib/x86_64-linux-gnu&quot; &quot;-L&quot; &quot;/home/butler/packs/exa/target/release/build/openssl-sys-e0bd245bf09b1a3f/out&quot; &quot;-L&quot; &quot;/home/butler/.multirust/toolchains/nightly/lib/rustlib/x86_64-unknown-linux-gnu/lib&quot; &quot;-L&quot; &quot;/home/butler/packs/exa/.rust/lib/x86_64-unknown-linux-gnu&quot; &quot;-L&quot; &quot;/home/butler/packs/exa/lib/x86_64-unknown-linux-gnu&quot; &quot;-Wl,-Bstatic&quot; &quot;-Wl,-Bdynamic&quot; &quot;-l&quot; &quot;rt&quot; &quot;-l&quot; &quot;ssl&quot; &quot;-l&quot; &quot;crypto&quot; &quot;-l&quot; &quot;dl&quot; &quot;-l&quot; &quot;z&quot; &quot;-l&quot; &quot;ssl&quot; &quot;-l&quot; &quot;crypto&quot; &quot;-l&quot; &quot;z&quot; &quot;-l&quot; &quot;c&quot; &quot;-l&quot; &quot;m&quot; &quot;-l&quot; &quot;dl&quot; &quot;-l&quot; &quot;pthread&quot; &quot;-l&quot; &quot;rt&quot; &quot;-l&quot; &quot;gcc_s&quot; &quot;-l&quot; &quot;pthread&quot; &quot;-l&quot; &quot;c&quot; &quot;-l&quot; &quot;m&quot; &quot;-Wl,-rpath,$ORIGIN/../../../../.multirust/toolchains/nightly/lib/rustlib/x86_64-unknown-linux-gnu/lib&quot; &quot;-Wl,-rpath,/usr/local/lib/rustlib/x86_64-unknown-linux-gnu/lib&quot; &quot;-l&quot; &quot;compiler-rt&quot;
note: /tmp/rustc.0qWCH5Q46Uym/liblibssh2_sys-63d236645b9d2140.rlib(openssl.c.o): In function `_libssh2_rsa_new':
openssl.c:(.text._libssh2_rsa_new+0x0): multiple definition of `_libssh2_rsa_new'
/tmp/rustc.0qWCH5Q46Uym/liblibgit2_sys-92cc88eed912bce1.rlib(openssl.c.o):openssl.c:(.text._libssh2_rsa_new+0x0): first defined here
/tmp/rustc.0qWCH5Q46Uym/liblibssh2_sys-63d236645b9d2140.rlib(openssl.c.o): In function `_libssh2_dsa_new':
openssl.c:(.text._libssh2_dsa_new+0x0): multiple definition of `_libssh2_dsa_new'
/tmp/rustc.0qWCH5Q46Uym/liblibgit2_sys-92cc88eed912bce1.rlib(openssl.c.o):openssl.c:(.text._libssh2_dsa_new+0x0): first defined here
/tmp/rustc.0qWCH5Q46Uym/liblibssh2_sys-63d236645b9d2140.rlib(openssl.c.o): In function `_libssh2_cipher_init':
openssl.c:(.text._libssh2_cipher_init+0x0): multiple definition of `_libssh2_cipher_init'
..... more lines"><pre class="notranslate"><code class="notranslate">Compiling exa v0.3.0 (file:///home/butler/packs/exa)
error: linking with `cc` failed: exit code: 1
note: "cc" "-Wl,--as-needed" "-m64" "-L" "/home/butler/.multirust/toolchains/nightly/lib/rustlib/x86_64-unknown-linux-gnu/lib" "/home/butler/packs/exa/target/release/exa.0.o" "-o" "/home/butler/packs/exa/target/release/exa" "-Wl,--gc-sections" "-pie" "-Wl,-O1" "-nodefaultlibs" "-Wl,--whole-archive" "/tmp/rustc.0qWCH5Q46Uym/liblibgit2_sys-92cc88eed912bce1.rlib" "-Wl,--no-whole-archive" "-Wl,--whole-archive" "/tmp/rustc.0qWCH5Q46Uym/liblibssh2_sys-63d236645b9d2140.rlib" "-Wl,--no-whole-archive" "-Wl,--whole-archive" "/tmp/rustc.0qWCH5Q46Uym/libopenssl_sys-e0bd245bf09b1a3f.rlib" "-Wl,--no-whole-archive" "-Wl,--whole-archive" "/tmp/rustc.0qWCH5Q46Uym/libstd-35017696.rlib" "-Wl,--no-whole-archive" "-Wl,--whole-archive" "/tmp/rustc.0qWCH5Q46Uym/liballoc_jemalloc-35017696.rlib" "-Wl,--no-whole-archive" "-L" "/home/butler/packs/exa/target/release" "-L" "/home/butler/packs/exa/target/release/deps" "-L" "/home/butler/packs/exa/target/release/build/libgit2-sys-92cc88eed912bce1/out/lib" "-L" "/home/butler/packs/exa/target/release/build/libssh2-sys-63d236645b9d2140/out/lib" "-L" "/usr/lib/x86_64-linux-gnu" "-L" "/home/butler/packs/exa/target/release/build/libssh2-sys-63d236645b9d2140/out/lib" "-L" "/usr/lib/x86_64-linux-gnu" "-L" "/usr/lib/x86_64-linux-gnu" "-L" "/home/butler/packs/exa/target/release/build/openssl-sys-e0bd245bf09b1a3f/out" "-L" "/home/butler/.multirust/toolchains/nightly/lib/rustlib/x86_64-unknown-linux-gnu/lib" "-L" "/home/butler/packs/exa/.rust/lib/x86_64-unknown-linux-gnu" "-L" "/home/butler/packs/exa/lib/x86_64-unknown-linux-gnu" "-Wl,-Bstatic" "-Wl,-Bdynamic" "-l" "rt" "-l" "ssl" "-l" "crypto" "-l" "dl" "-l" "z" "-l" "ssl" "-l" "crypto" "-l" "z" "-l" "c" "-l" "m" "-l" "dl" "-l" "pthread" "-l" "rt" "-l" "gcc_s" "-l" "pthread" "-l" "c" "-l" "m" "-Wl,-rpath,$ORIGIN/../../../../.multirust/toolchains/nightly/lib/rustlib/x86_64-unknown-linux-gnu/lib" "-Wl,-rpath,/usr/local/lib/rustlib/x86_64-unknown-linux-gnu/lib" "-l" "compiler-rt"
note: /tmp/rustc.0qWCH5Q46Uym/liblibssh2_sys-63d236645b9d2140.rlib(openssl.c.o): In function `_libssh2_rsa_new':
openssl.c:(.text._libssh2_rsa_new+0x0): multiple definition of `_libssh2_rsa_new'
/tmp/rustc.0qWCH5Q46Uym/liblibgit2_sys-92cc88eed912bce1.rlib(openssl.c.o):openssl.c:(.text._libssh2_rsa_new+0x0): first defined here
/tmp/rustc.0qWCH5Q46Uym/liblibssh2_sys-63d236645b9d2140.rlib(openssl.c.o): In function `_libssh2_dsa_new':
openssl.c:(.text._libssh2_dsa_new+0x0): multiple definition of `_libssh2_dsa_new'
/tmp/rustc.0qWCH5Q46Uym/liblibgit2_sys-92cc88eed912bce1.rlib(openssl.c.o):openssl.c:(.text._libssh2_dsa_new+0x0): first defined here
/tmp/rustc.0qWCH5Q46Uym/liblibssh2_sys-63d236645b9d2140.rlib(openssl.c.o): In function `_libssh2_cipher_init':
openssl.c:(.text._libssh2_cipher_init+0x0): multiple definition of `_libssh2_cipher_init'
..... more lines
</code></pre></div>
<p dir="auto">Exa depends on libssh2-sys and libgit2-sys. If pkg-config cannot find libssh2, it's compiled locally by build.rs while building libssh2-sys and is embedded into resulting rlib as expected. For some reason, it's also present in libgit2-sys that doesn't depend on libssh2 directly. So we get second copy and linkage breaks.</p>
<p dir="auto">This bug appeared after this commit: <a class="commit-link" data-hovercard-type="commit" data-hovercard-url="https://github.com/rust-lang/rust/commit/9bc8e6d1472a57441afe3592078838d2bc767996/hovercard" href="https://github.com/rust-lang/rust/commit/9bc8e6d1472a57441afe3592078838d2bc767996"><tt>9bc8e6d</tt></a></p>
<p dir="auto">Here is original bug report for reference: <a class="issue-link js-issue-link" data-error-text="Failed to load title" data-id="94257913" data-permission-text="Title is private" data-url="https://github.com/ogham/exa/issues/72" data-hovercard-type="issue" data-hovercard-url="/ogham/exa/issues/72/hovercard" href="https://github.com/ogham/exa/issues/72">ogham/exa#72</a></p>
<p dir="auto"><code class="notranslate">cargo new mycrate</code></p>
<p dir="auto">Add to <code class="notranslate">Cargo.toml</code>:</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="[dependencies]
num = &quot;*&quot;"><pre class="notranslate"><code class="notranslate">[dependencies]
num = "*"
</code></pre></div>
<p dir="auto">Make empty <code class="notranslate">x.rs</code> file: <code class="notranslate">touch mycrate/src/x.rs</code></p>
<p dir="auto">Contents of <code class="notranslate">mycrate/src/lib.rs</code>:</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="extern crate num;
use num as num_export;
use self::x::*;"><pre class="notranslate"><code class="notranslate">extern crate num;
use num as num_export;
use self::x::*;
</code></pre></div>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="$ cargo build
   Compiling issue v0.1.0 (file:///home/stephen/Desktop/rust/issue)
src/lib.rs:2:5: 2:22 error: unresolved import (maybe you meant `num as num_export::*`?)
src/lib.rs:2 use num as num_export;
                 ^~~~~~~~~~~~~~~~~
error: aborting due to previous error
Could not compile `issue`.

To learn more, run the command again with --verbose."><pre class="notranslate"><code class="notranslate">$ cargo build
   Compiling issue v0.1.0 (file:///home/stephen/Desktop/rust/issue)
src/lib.rs:2:5: 2:22 error: unresolved import (maybe you meant `num as num_export::*`?)
src/lib.rs:2 use num as num_export;
                 ^~~~~~~~~~~~~~~~~
error: aborting due to previous error
Could not compile `issue`.

To learn more, run the command again with --verbose.
</code></pre></div>
<p dir="auto">Try removing the <code class="notranslate">use self::x::*;</code> line and everything will work just fine.</p>
<ul dir="auto">
<li>OS: Ubuntu 15.04 (beta)</li>
<li><code class="notranslate">rustc --version</code>: <code class="notranslate">rustc 1.1.0 (35ceea399 2015-06-19)</code></li>
</ul>