Cannot build simple hello world app in Rust


#1

I get some wierd architecture error when trying to build a simple hello world app on OS X 10.11.2 ! :sob:

Just upgraded to 1.6, I dabbled in Rust a few months ago and didn’t have issues like this.

Here’s an example session:

cargo new myrust --bin
cd myrust
cargo build --verbose

Compiling myrust v0.1.0 (file:///Users/frank/myrust)
Running rustc src/main.rs --crate-name myrust --crate-type bin -g --out-dir /Users/frank/myrust/target/debug --emit=dep-info,link -L dependency=/Users/frank/myrust/target/debug -L dependency=/Users/frank/myrust/target/debug/deps
error: linking with cc failed: exit code: 1
note: “cc” “-m64” “-L” “/usr/local/lib/rustlib/x86_64-apple-darwin/lib” “/Users/frank/myrust/target/debug/myrust.0.o” “-o” “/Users/frank/myrust/target/debug/myrust” “-Wl,-dead_strip” “-nodefaultlibs” “-L” “/Users/frank/myrust/target/debug” “-L” “/Users/frank/myrust/target/debug/deps” “-L” “/usr/local/lib/rustlib/x86_64-apple-darwin/lib” “/usr/local/lib/rustlib/x86_64-apple-darwin/lib/libstd-ca9f0d77.rlib” “/usr/local/lib/rustlib/x86_64-apple-darwin/lib/libcollections-ca9f0d77.rlib” “/usr/local/lib/rustlib/x86_64-apple-darwin/lib/librustc_unicode-ca9f0d77.rlib” “/usr/local/lib/rustlib/x86_64-apple-darwin/lib/librand-ca9f0d77.rlib” “/usr/local/lib/rustlib/x86_64-apple-darwin/lib/liballoc-ca9f0d77.rlib” “/usr/local/lib/rustlib/x86_64-apple-darwin/lib/liballoc_jemalloc-ca9f0d77.rlib” “/usr/local/lib/rustlib/x86_64-apple-darwin/lib/liblibc-ca9f0d77.rlib” “/usr/local/lib/rustlib/x86_64-apple-darwin/lib/libcore-ca9f0d77.rlib” “-l” “System” “-l” “pthread” “-l” “c” “-l” “m” “-l” "compiler-rt"
note: ld: targeted OS version does not support use of thread local variables in __ZN10sys_common11thread_info14current_thread20h67a0745d7f70577eJAsE 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 myrust.

Caused by:
Process didn’t exit successfully: rustc src/main.rs --crate-name myrust --crate-type bin -g --out-dir /Users/frank/myrust/target/debug --emit=dep-info,link -L dependency=/Users/frank/myrust/target/debug -L dependency=/Users/frank/myrust/target/debug/deps (exit code: 101)

Any ideas what I should do?

Thanks!


#2

Works for me on 10.10.5:

$$ rustc --version
rustc 1.6.0 (c30b771ad 2016-01-19)
$$ cargo new myrust --bin
$$ cd myrust
$$ cargo build --verbose
   Compiling myrust v0.1.0 (file:///private/tmp/myrust)
     Running `rustc src/main.rs --crate-name myrust --crate-type bin -g --out-dir /private/tmp/myrust/target/debug --emit=dep-info,link -L dependency=/private/tmp/myrust/target/debug -L dependency=/private/tmp/myrust/target/debug/deps`
$$ sw_vers -productVersion
10.10.5

The error message you mention is found in the issue, https://github.com/rust-lang/rust/pull/25858 . Is it possible that you have somehow configured your system toolchain to target OSX 10.6?

It seems unlikely that rust would be categorically broken on 10.11.2, but I suppose it’s possible. Anyone else want to weigh in?


#3

@sorear Thanks for reply. I just upgraded to the latest OS patch (10.11.3) I then launched Xcode (half wondering if something in there might have configured my toolchain wrong) and it asked me if it could install some ‘extra components’, so I went a long with this.

I then recreated the project as above and I’m glad to say it works now!

I’m not sure what was up with the previous OS version, but I definitely didn’t get the prompt from Xcode before the patch.