[rust-dev] Issues linking a static Rust library

Tahia Khan tahia.khan at gmail.com
Tue Oct 7 13:03:32 PDT 2014

Hey all! Rust newbie here. I'm having some problems including a static Rust
library inside of an Objective-C project on XCode.

I was looking through rustc source code (specifically /back/link.rs) and I
saw that rlibs and staticlibs are built very similarly (in fact link_rlib
is called inside of link_staticlib). According to the comments above the
link_rlib function in link.rs, non-object "magical files" are tacked onto
the end of archive files for rlibs/staticlibs. I inspected my staticlib
with otool and confirmed that there are a bunch of non-object files at the

libtreble.a(r-std-std-4e7c5e5c.0.bytecode.deflate): is not an object file
libtreble.a(r-rand-rand-4e7c5e5c.0.bytecode.deflate): is not an object file
libtreble.a(r-sync-sync-4e7c5e5c.0.bytecode.deflate): is not an object file
libtreble.a(r-rustrt-rustrt-4e7c5e5c.0.bytecode.deflate): is not an object
libtreble.a(r-collections-collections-4e7c5e5c.0.bytecode.deflate): is not
an object file
libtreble.a(r-alloc-alloc-4e7c5e5c.0.bytecode.deflate): is not an object
libtreble.a(r-libc-libc-4e7c5e5c.0.bytecode.deflate): is not an object file
libtreble.a(r-unicode-unicode-4e7c5e5c.0.bytecode.deflate): is not an
object file
libtreble.a(r-core-core-4e7c5e5c.0.bytecode.deflate): is not an object file

When I try to build my Xcode project, my build fails with the following

ld: in
archive member 'r-std-std-4e7c5e5c.0.bytecode.deflate' with length 999896
is not mach-o or llvm bitcode for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see

It looks like the Xcode linker hits the very first non-object file then
isn't able to determine the architecture of the archive. Does anyone know
if there's some way to exclude these non-object files in a staticlib/rlib?
Or if there's some other way to avoid this build issue with the XCode

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.mozilla.org/pipermail/rust-dev/attachments/20141007/afe35aa0/attachment.html>

More information about the Rust-dev mailing list