Failed to run custom build command for `backtrace-sys v0.1.31


I'm new to Rust and I'm about to start my very first project. I want to build something that requires web scraping and saw in the Cookbook that I can use the reqwest crate to perform HTTP requests.

Unfortunately, I got stuck immediately even before getting to write a single line of code :frowning:
I added reqwest = "0.9.20" as a dependency in my Cargo.toml file and then ran cargo build.

The project fails to compile with the following error:

error: failed to run custom build command for `backtrace-sys v0.1.31`

Caused by:
  process didn't exit successfully: `/Users/andresovela/rustdev/project_tracker/target/debug/build/backtrace-sys-28d20b1249f676c5/build-script-build` (exit code: 1)

Any ideas?

EDIT: I'm on macOS 10.14.6 (Mojave), latest stable Rust.

Do you have the normal MacOS non-rust development tools installed? As I recall backtrace-sys uses the system backtrace handler, meaning it needs to compile code native to the system for it to be able to work.

The installation documentation of it also seems to confirm this:

Note that this crate requires cc and ar to be present on Unix systems when libbacktrace is used (which is the default). For configuring C compilers see the cc crate documentation.

And MacOSX is a unix system.

I did see that in the documentation but I don't really understand what can be going wrong there. I didn't see anything in the documentation about needing to have anything installed to be able to use cc.

Do you mean the "Command Line Tools" from Xcode? Because I do have them installed already.

No clue, never used Mac's. ^.^;

Do you have a cc and an ar program on your path though? What versions? cc --version and ar --version perhaps, depending on the types installed?

Are cc and ar binaries that need to be installed? As far as I understand they're just some other Rust libraries that reqwest depends on. Shouldn't cargo manage the "installation" of those already?

Ok, just checked and they are binaries and are already in my path.

They aren't libraries, they are the compiler and archive builder for normal C code, they should come with any normal system development tools.

What versions are they? What's the output of calling --version on each?

In that case need the full build log I'd think? Can you gist it or so?

Here you go.

1 Like

So it's happening when it runs ar, with an error of malformed object, never seen this error before... To the Google!

So it seems this is not an uncommon error on Mac systems for any native code compilation (responses from everything from C to Haskell and more).

Some quick googling reveals:

  • Try running xcode-select --install to rebuild the pathing.
  • Make sure you don't have an alternative ar, only the official Apple one should be used, so make sure whereis ar or whence ar only resolves /usr/bin/ar and that you don't have another one ahead of it in the path like at /opt/local/bin/ar (this seems to be cause by broken migrations in macport or so).
  • Make sure you don't have cctools installed via brew, if you do remove them via brew uninstall -f cctools and run xcode-select --install again to repair the system.

Beyond that might need to wait for a Mac person to come around. ^.^;

1 Like

Thanks for pointing me in the right direction :slight_smile:

I followed this recommendation and now it compiles!

I also had to install MacPorts and had to install cctools with it.

1 Like

Awesome! Great to hear! ^.^

For note, from what I was reading macports installs its own ar and runlib that don't work quite identically to the one from xcode, I saw many warnings about using macports on a system (where brew is recommended instead), and apparently even brew removed cctools a while back, can't install it anymore as xcode's should be used instead. I don't really know what either are (though from my guessing from usages macports seems like the BSD Ports package system and brew seems a lot like apt or yum?), so if you don't need macports it might be good to wipe it and setup xcode again fully. :slight_smile:

Though considering it's working now, probably best not to touch anything, lol.

I did notice that when I was installing cctools MacPorts also installed some llvm stuff, I hope it didn't screw up the system one.

1 Like