<p dir="auto">Rust code on SO right now looks pretty nasty. Most egregiously it interprets the lifetime syntax as the start of a string, yielding hilarious results.</p>
<p dir="auto">Here's the project that SO uses to highlight code:</p>
<p dir="auto"><a href="https://code.google.com/p/google-code-prettify/" rel="nofollow">https://code.google.com/p/google-code-prettify/</a></p>
<p dir="auto">It has no "Rust" option, so I have no idea what language SO is currently using to highlight our code. Implement proper Rust support, and once it's accepted into Prettify we'll try to contact SO to get them to update their version.</p>
<p dir="auto">Hi, I'm trying to make a really really simple hello world program in Rust using a custom library through Cargo, and I'm getting the error:</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="   Compiling rstestlib v0.0.1 (file:///Users/benanderson/Desktop/rstest)
   Compiling rstest v0.0.1 (file:///Users/benanderson/Desktop/rstest)
error: linking with `cc` failed: exit code: 1
note: cc '-m64' '-L' '/usr/local/lib/rustlib/x86_64-apple-darwin/lib' '-o' '/Users/benanderson/Desktop/rstest/target/rstest' '/Users/benanderson/Desktop/rstest/target/rstest.o' '-Wl,-force_load,/usr/local/lib/rustlib/x86_64-apple-darwin/lib/libmorestack.a' '-nodefaultlibs' '-fno-lto' '-Wl,-dead_strip' '/usr/local/lib/rustlib/x86_64-apple-darwin/lib/libnative-4e7c5e5c.rlib' '/Users/benanderson/Desktop/rstest/target/deps/librstestlib-1806f5315b450877.rlib' '/usr/local/lib/rustlib/x86_64-apple-darwin/lib/libstd-4e7c5e5c.rlib' '/usr/local/lib/rustlib/x86_64-apple-darwin/lib/librand-4e7c5e5c.rlib' '/usr/local/lib/rustlib/x86_64-apple-darwin/lib/libsync-4e7c5e5c.rlib' '/usr/local/lib/rustlib/x86_64-apple-darwin/lib/librustrt-4e7c5e5c.rlib' '/usr/local/lib/rustlib/x86_64-apple-darwin/lib/libcollections-4e7c5e5c.rlib' '/usr/local/lib/rustlib/x86_64-apple-darwin/lib/libunicode-4e7c5e5c.rlib' '/usr/local/lib/rustlib/x86_64-apple-darwin/lib/liballoc-4e7c5e5c.rlib' '/usr/local/lib/rustlib/x86_64-apple-darwin/lib/liblibc-4e7c5e5c.rlib' '/usr/local/lib/rustlib/x86_64-apple-darwin/lib/libcore-4e7c5e5c.rlib' '-L' '/Users/benanderson/Desktop/rstest/target' '-L' '/Users/benanderson/Desktop/rstest/target/deps' '-L' '/Users/benanderson/Desktop/rstest/.rust' '-L' '/Users/benanderson/Desktop/rstest' '-lSystem' '-lpthread' '-lc' '-lm' '-lcompiler-rt'
note: ld: warning: directory not found for option '-L/Users/benanderson/Desktop/rstest/.rust'
ld: archive has no table of contents file '/Users/benanderson/Desktop/rstest/target/deps/librstestlib-1806f5315b450877.rlib' for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)

error: aborting due to previous error
Could not compile `rstest`."><pre class="notranslate"><code class="notranslate">   Compiling rstestlib v0.0.1 (file:///Users/benanderson/Desktop/rstest)
   Compiling rstest v0.0.1 (file:///Users/benanderson/Desktop/rstest)
error: linking with `cc` failed: exit code: 1
note: cc '-m64' '-L' '/usr/local/lib/rustlib/x86_64-apple-darwin/lib' '-o' '/Users/benanderson/Desktop/rstest/target/rstest' '/Users/benanderson/Desktop/rstest/target/rstest.o' '-Wl,-force_load,/usr/local/lib/rustlib/x86_64-apple-darwin/lib/libmorestack.a' '-nodefaultlibs' '-fno-lto' '-Wl,-dead_strip' '/usr/local/lib/rustlib/x86_64-apple-darwin/lib/libnative-4e7c5e5c.rlib' '/Users/benanderson/Desktop/rstest/target/deps/librstestlib-1806f5315b450877.rlib' '/usr/local/lib/rustlib/x86_64-apple-darwin/lib/libstd-4e7c5e5c.rlib' '/usr/local/lib/rustlib/x86_64-apple-darwin/lib/librand-4e7c5e5c.rlib' '/usr/local/lib/rustlib/x86_64-apple-darwin/lib/libsync-4e7c5e5c.rlib' '/usr/local/lib/rustlib/x86_64-apple-darwin/lib/librustrt-4e7c5e5c.rlib' '/usr/local/lib/rustlib/x86_64-apple-darwin/lib/libcollections-4e7c5e5c.rlib' '/usr/local/lib/rustlib/x86_64-apple-darwin/lib/libunicode-4e7c5e5c.rlib' '/usr/local/lib/rustlib/x86_64-apple-darwin/lib/liballoc-4e7c5e5c.rlib' '/usr/local/lib/rustlib/x86_64-apple-darwin/lib/liblibc-4e7c5e5c.rlib' '/usr/local/lib/rustlib/x86_64-apple-darwin/lib/libcore-4e7c5e5c.rlib' '-L' '/Users/benanderson/Desktop/rstest/target' '-L' '/Users/benanderson/Desktop/rstest/target/deps' '-L' '/Users/benanderson/Desktop/rstest/.rust' '-L' '/Users/benanderson/Desktop/rstest' '-lSystem' '-lpthread' '-lc' '-lm' '-lcompiler-rt'
note: ld: warning: directory not found for option '-L/Users/benanderson/Desktop/rstest/.rust'
ld: archive has no table of contents file '/Users/benanderson/Desktop/rstest/target/deps/librstestlib-1806f5315b450877.rlib' for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)

error: aborting due to previous error
Could not compile `rstest`.
</code></pre></div>
<p dir="auto">I have a lib rstestlib, containing a lib.rs with this inside it:</p>
<div class="highlight highlight-source-rust notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="pub fn test() {
    println!(&quot;Test&quot;);
}"><pre class="notranslate"><span class="pl-k">pub</span> <span class="pl-k">fn</span> <span class="pl-en">test</span><span class="pl-kos">(</span><span class="pl-kos">)</span> <span class="pl-kos">{</span>
    <span class="pl-en">println</span><span class="pl-en">!</span><span class="pl-kos">(</span><span class="pl-s">"Test"</span><span class="pl-kos">)</span><span class="pl-kos">;</span>
<span class="pl-kos">}</span></pre></div>
<p dir="auto">And the rstest program has a main.rs with:</p>
<div class="highlight highlight-source-rust notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="extern crate rstestlib;
fn main() {
    rstestlib::test();
}"><pre class="notranslate"><span class="pl-k">extern</span> <span class="pl-k">crate</span> rstestlib<span class="pl-kos">;</span>
<span class="pl-k">fn</span> <span class="pl-en">main</span><span class="pl-kos">(</span><span class="pl-kos">)</span> <span class="pl-kos">{</span>
    rstestlib<span class="pl-kos">::</span><span class="pl-en">test</span><span class="pl-kos">(</span><span class="pl-kos">)</span><span class="pl-kos">;</span>
<span class="pl-kos">}</span></pre></div>
<p dir="auto">The rstest program has this as a Cargo.toml file:</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="[package]
name = &quot;rstest&quot;
version = &quot;0.0.1&quot;
authors = [&quot;GravityScore &lt;gravityscore@gmail.com&gt;&quot;]

[dependencies.rstestlib]
path = &quot;../rstestlib&quot;"><pre class="notranslate"><code class="notranslate">[package]
name = "rstest"
version = "0.0.1"
authors = ["GravityScore &lt;gravityscore@gmail.com&gt;"]

[dependencies.rstestlib]
path = "../rstestlib"
</code></pre></div>
<p dir="auto">And the rstestlib program has this as a Cargo.toml:</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="[package]
name = &quot;rstestlib&quot;
version = &quot;0.0.1&quot;
authors = [&quot;GravityScore &lt;gravityscore@gmail.com&gt;&quot;]"><pre class="notranslate"><code class="notranslate">[package]
name = "rstestlib"
version = "0.0.1"
authors = ["GravityScore &lt;gravityscore@gmail.com&gt;"]
</code></pre></div>
<p dir="auto">I've just reinstalled rust using the 1 line console command from the Cargo website. The output of rustc -v is <code class="notranslate">rustc 0.13.0-nightly (0a5e7f359 2014-11-03 23:16:55 +0000)</code>. I've had this problem for a while now, and it's really disappointing because I love rust so much, but I can't use it at all anymore.</p>
<p dir="auto">I've tried running <code class="notranslate">ranlib target/deps/librstestlib*</code> as some internet sources (eg. <a href="http://stackoverflow.com/questions/4445735/why-do-i-get-ld-in-libunittest-a-archive-has-no-table-of-contents-when-bui" rel="nofollow">here</a>) suggest, but when I do this I get a bunch of undefined symbols for architecture, and a note saying the .rlib file was not built for the current architecture I'm trying to build for (which is x86_64):</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="Bens-MacBook-Pro-4:rstest benanderson$ ranlib target/deps/librstestlib*
Bens-MacBook-Pro-4:rstest benanderson$ cargo build
   Compiling rstest v0.0.1 (file:///Users/benanderson/Desktop/rstest)
error: linking with `cc` failed: exit code: 1
note: cc '-m64' '-L' '/usr/local/lib/rustlib/x86_64-apple-darwin/lib' '-o' '/Users/benanderson/Desktop/rstest/target/rstest' '/Users/benanderson/Desktop/rstest/target/rstest.o' '-Wl,-force_load,/usr/local/lib/rustlib/x86_64-apple-darwin/lib/libmorestack.a' '-nodefaultlibs' '-fno-lto' '-Wl,-dead_strip' '/usr/local/lib/rustlib/x86_64-apple-darwin/lib/libnative-4e7c5e5c.rlib' '/Users/benanderson/Desktop/rstest/target/deps/librstestlib-1806f5315b450877.rlib' '/usr/local/lib/rustlib/x86_64-apple-darwin/lib/libstd-4e7c5e5c.rlib' '/usr/local/lib/rustlib/x86_64-apple-darwin/lib/libsync-4e7c5e5c.rlib' '/usr/local/lib/rustlib/x86_64-apple-darwin/lib/librustrt-4e7c5e5c.rlib' '/usr/local/lib/rustlib/x86_64-apple-darwin/lib/libcollections-4e7c5e5c.rlib' '/usr/local/lib/rustlib/x86_64-apple-darwin/lib/libunicode-4e7c5e5c.rlib' '/usr/local/lib/rustlib/x86_64-apple-darwin/lib/liballoc-4e7c5e5c.rlib' '/usr/local/lib/rustlib/x86_64-apple-darwin/lib/liblibc-4e7c5e5c.rlib' '/usr/local/lib/rustlib/x86_64-apple-darwin/lib/librand-4e7c5e5c.rlib' '/usr/local/lib/rustlib/x86_64-apple-darwin/lib/libcore-4e7c5e5c.rlib' '-L' '/Users/benanderson/Desktop/rstest/target' '-L' '/Users/benanderson/Desktop/rstest/target/deps' '-L' '/Users/benanderson/Desktop/rstest/.rust' '-L' '/Users/benanderson/Desktop/rstest' '-lSystem' '-lpthread' '-lc' '-lm' '-lcompiler-rt'
note: ld: warning: directory not found for option '-L/Users/benanderson/Desktop/rstest/.rust'

ld: warning: ignoring file /Users/benanderson/Desktop/rstest/target/deps/librstestlib-1806f5315b450877.rlib, file was built for archive which is not the architecture being linked (x86_64): /Users/benanderson/Desktop/rstest/target/deps/librstestlib-1806f5315b450877.rlib

Undefined symbols for architecture x86_64:
  &quot;test::hb3734900dfb5a78ddaa&quot;, referenced from:
      main::h7d8e0789b2179c99faa in rstest.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)

error: aborting due to previous error
Could not compile `rstest`."><pre class="notranslate"><code class="notranslate">Bens-MacBook-Pro-4:rstest benanderson$ ranlib target/deps/librstestlib*
Bens-MacBook-Pro-4:rstest benanderson$ cargo build
   Compiling rstest v0.0.1 (file:///Users/benanderson/Desktop/rstest)
error: linking with `cc` failed: exit code: 1
note: cc '-m64' '-L' '/usr/local/lib/rustlib/x86_64-apple-darwin/lib' '-o' '/Users/benanderson/Desktop/rstest/target/rstest' '/Users/benanderson/Desktop/rstest/target/rstest.o' '-Wl,-force_load,/usr/local/lib/rustlib/x86_64-apple-darwin/lib/libmorestack.a' '-nodefaultlibs' '-fno-lto' '-Wl,-dead_strip' '/usr/local/lib/rustlib/x86_64-apple-darwin/lib/libnative-4e7c5e5c.rlib' '/Users/benanderson/Desktop/rstest/target/deps/librstestlib-1806f5315b450877.rlib' '/usr/local/lib/rustlib/x86_64-apple-darwin/lib/libstd-4e7c5e5c.rlib' '/usr/local/lib/rustlib/x86_64-apple-darwin/lib/libsync-4e7c5e5c.rlib' '/usr/local/lib/rustlib/x86_64-apple-darwin/lib/librustrt-4e7c5e5c.rlib' '/usr/local/lib/rustlib/x86_64-apple-darwin/lib/libcollections-4e7c5e5c.rlib' '/usr/local/lib/rustlib/x86_64-apple-darwin/lib/libunicode-4e7c5e5c.rlib' '/usr/local/lib/rustlib/x86_64-apple-darwin/lib/liballoc-4e7c5e5c.rlib' '/usr/local/lib/rustlib/x86_64-apple-darwin/lib/liblibc-4e7c5e5c.rlib' '/usr/local/lib/rustlib/x86_64-apple-darwin/lib/librand-4e7c5e5c.rlib' '/usr/local/lib/rustlib/x86_64-apple-darwin/lib/libcore-4e7c5e5c.rlib' '-L' '/Users/benanderson/Desktop/rstest/target' '-L' '/Users/benanderson/Desktop/rstest/target/deps' '-L' '/Users/benanderson/Desktop/rstest/.rust' '-L' '/Users/benanderson/Desktop/rstest' '-lSystem' '-lpthread' '-lc' '-lm' '-lcompiler-rt'
note: ld: warning: directory not found for option '-L/Users/benanderson/Desktop/rstest/.rust'

ld: warning: ignoring file /Users/benanderson/Desktop/rstest/target/deps/librstestlib-1806f5315b450877.rlib, file was built for archive which is not the architecture being linked (x86_64): /Users/benanderson/Desktop/rstest/target/deps/librstestlib-1806f5315b450877.rlib

Undefined symbols for architecture x86_64:
  "test::hb3734900dfb5a78ddaa", referenced from:
      main::h7d8e0789b2179c99faa in rstest.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)

error: aborting due to previous error
Could not compile `rstest`.
</code></pre></div>
<p dir="auto">But, if I run <code class="notranslate">lipo -info target/deps/librstestlib*</code>, it says the archive file was built for x86_64:</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="input file target/deps/librstestlib-1806f5315b450877.rlib is not a fat file
Non-fat file: target/deps/librstestlib-1806f5315b450877.rlib is architecture: x86_64"><pre class="notranslate"><code class="notranslate">input file target/deps/librstestlib-1806f5315b450877.rlib is not a fat file
Non-fat file: target/deps/librstestlib-1806f5315b450877.rlib is architecture: x86_64
</code></pre></div>
<p dir="auto">This happens with any library I try and link, ones from GitHub or locally. I'm running OSX Yosemite (10.10), with the latest Xcode (6.1) and OSX SDKs installed. I get the same problem if I bypass Cargo and compile using rustc directly as well, so it's not a Cargo problem. I used the command <code class="notranslate">rustc -L"../rstestlib/target" src/main.rs</code>.</p>
<p dir="auto">Does someone know what's going on here? I'm really stuck and can't figure out why this is happening. I really love Rust and really appreciate all the hard work that's gone into making it - it is fantastic. But it's not working at the moment, which is really disappointing and very limiting if I can't link against libraries.</p>