eonil
eonil

Reputation: 86095

Cargo fails to link with `cc` due to signal 10 when run from inside Xcode 8

I got a strange error while running cargo in an macOS app from inside Xcode 8:

Eonil$ cargo clean
[~/Temp/repotest1/ag] (master)
Eonil$ cargo build
   Compiling ag v0.1.0 (file:///Users/Eonil/Temp/repotest1/ag)
error: linking with `cc` failed: signal: 10
  |
  = note: "cc" "-m64" "-L" "/Users/Eonil/.rustup/toolchains/stable-x86_64-apple-darwin/lib/rustlib/x86_64-apple-darwin/lib" "/Users/Eonil/Temp/repotest1/ag/target/debug/ag.0.o" "-o" "/Users/Eonil/Temp/repotest1/ag/target/debug/ag" "-Wl,-dead_strip" "-nodefaultlibs" "-L" "/Users/Eonil/Temp/repotest1/ag/target/debug/deps" "-L" "/Users/Eonil/.rustup/toolchains/stable-x86_64-apple-darwin/lib/rustlib/x86_64-apple-darwin/lib" "/Users/Eonil/.rustup/toolchains/stable-x86_64-apple-darwin/lib/rustlib/x86_64-apple-darwin/lib/libstd-f5a209a9.rlib" "/Users/Eonil/.rustup/toolchains/stable-x86_64-apple-darwin/lib/rustlib/x86_64-apple-darwin/lib/libpanic_unwind-f5a209a9.rlib" "/Users/Eonil/.rustup/toolchains/stable-x86_64-apple-darwin/lib/rustlib/x86_64-apple-darwin/lib/libunwind-f5a209a9.rlib" "/Users/Eonil/.rustup/toolchains/stable-x86_64-apple-darwin/lib/rustlib/x86_64-apple-darwin/lib/librand-f5a209a9.rlib" "/Users/Eonil/.rustup/toolchains/stable-x86_64-apple-darwin/lib/rustlib/x86_64-apple-darwin/lib/libcollections-f5a209a9.rlib" "/Users/Eonil/.rustup/toolchains/stable-x86_64-apple-darwin/lib/rustlib/x86_64-apple-darwin/lib/librustc_unicode-f5a209a9.rlib" "/Users/Eonil/.rustup/toolchains/stable-x86_64-apple-darwin/lib/rustlib/x86_64-apple-darwin/lib/liballoc-f5a209a9.rlib" "/Users/Eonil/.rustup/toolchains/stable-x86_64-apple-darwin/lib/rustlib/x86_64-apple-darwin/lib/liballoc_jemalloc-f5a209a9.rlib" "/Users/Eonil/.rustup/toolchains/stable-x86_64-apple-darwin/lib/rustlib/x86_64-apple-darwin/lib/liblibc-f5a209a9.rlib" "/Users/Eonil/.rustup/toolchains/stable-x86_64-apple-darwin/lib/rustlib/x86_64-apple-darwin/lib/libcore-f5a209a9.rlib" "/Users/Eonil/.rustup/toolchains/stable-x86_64-apple-darwin/lib/rustlib/x86_64-apple-darwin/lib/libcompiler_builtins-f5a209a9.rlib" "-l" "System" "-l" "pthread" "-l" "c" "-l" "m"
  = note: 

error: aborting due to previous error

error: Could not compile `ag`.

To learn more, run the command again with --verbose.

Why do I get this error and how to fix this?

Upvotes: 1

Views: 141

Answers (1)

eonil
eonil

Reputation: 86095

The environment variable MallocNanoZone is set to 1. Remove it or set it to 0 and the problem magically disappears.

I don't know why this happens. In my case, the error occurred while running cargo under an Xcode debugging context using NSTask. Xcode sets MallocNanoZone=1 automatically, and it changes some memory management behavior which is not friendly with cargo execution.

Upvotes: 2

Related Questions