TimNN/cargo-lipo

error: linking with `cc` failed: exit code: 1 in Xcode 9.4.1

Closed this issue ยท 8 comments

cargo lipo works fine in mac terminal, but I will get error: linking with cc failed: exit code: 1 in Xcode when I run custom script.

rustc -vV
rustc 1.30.0-nightly (b2028828d 2018-08-16)
binary: rustc
commit-hash: b2028828db7e4870cb6a310f8ad8169ac9ea134d
commit-date: 2018-08-16
host: x86_64-apple-darwin
release: 1.30.0-nightly
LLVM version: 7.0
cc -v
Apple LLVM version 9.1.0 (clang-902.0.39.2)
Target: x86_64-apple-darwin17.5.0
Thread model: posix
InstalledDir: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin
clang -v
Apple LLVM version 9.1.0 (clang-902.0.39.2)
Target: x86_64-apple-darwin17.5.0
Thread model: posix
InstalledDir: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin

error detail:

  = note: "cc" "-m64" "-L" "/Users/zoey.weng/.rustup/toolchains/nightly-x86_64-apple-darwin/lib/rustlib/x86_64-apple-darwin/lib" "/Users/zoey.weng/Desktop/Study/PJToDo/PJToDo/Rust/pj_to_do_corelib/target/debug/build/security-framework-sys-69682004e1447249/build_script_build-69682004e1447249.build_script_build0.rcgu.o" "/Users/zoey.weng/Desktop/Study/PJToDo/PJToDo/Rust/pj_to_do_corelib/target/debug/build/security-framework-sys-69682004e1447249/build_script_build-69682004e1447249.build_script_build1.rcgu.o" "/Users/zoey.weng/Desktop/Study/PJToDo/PJToDo/Rust/pj_to_do_corelib/target/debug/build/security-framework-sys-69682004e1447249/build_script_build-69682004e1447249.build_script_build2.rcgu.o" "/Users/zoey.weng/Desktop/Study/PJToDo/PJToDo/Rust/pj_to_do_corelib/target/debug/build/security-framework-sys-69682004e1447249/build_script_build-69682004e1447249.build_script_build3.rcgu.o" "/Users/zoey.weng/Desktop/Study/PJToDo/PJToDo/Rust/pj_to_do_corelib/target/debug/build/security-framework-sys-69682004e1447249/build_script_build-69682004e1447249.build_script_build4.rcgu.o" "/Users/zoey.weng/Desktop/Study/PJToDo/PJToDo/Rust/pj_to_do_corelib/target/debug/build/security-framework-sys-69682004e1447249/build_script_build-69682004e1447249.build_script_build5.rcgu.o" "-o" "/Users/zoey.weng/Desktop/Study/PJToDo/PJToDo/Rust/pj_to_do_corelib/target/debug/build/security-framework-sys-69682004e1447249/build_script_build-69682004e1447249" "/Users/zoey.weng/Desktop/Study/PJToDo/PJToDo/Rust/pj_to_do_corelib/target/debug/build/security-framework-sys-69682004e1447249/build_script_build-69682004e1447249.crate.allocator.rcgu.o" "-Wl,-dead_strip" "-nodefaultlibs" "-L" "/Users/zoey.weng/Desktop/Study/PJToDo/PJToDo/Rust/pj_to_do_corelib/target/debug/deps" "-L" "/Users/zoey.weng/.rustup/toolchains/nightly-x86_64-apple-darwin/lib/rustlib/x86_64-apple-darwin/lib" "/Users/zoey.weng/.rustup/toolchains/nightly-x86_64-apple-darwin/lib/rustlib/x86_64-apple-darwin/lib/libstd-d9af9c9ee75d1d46.rlib" "/Users/zoey.weng/.rustup/toolchains/nightly-x86_64-apple-darwin/lib/rustlib/x86_64-apple-darwin/lib/libpanic_unwind-2ad58b52bb812329.rlib" "/Users/zoey.weng/.rustup/toolchains/nightly-x86_64-apple-darwin/lib/rustlib/x86_64-apple-darwin/lib/liballoc_jemalloc-1bc3e7256eaffb7f.rlib" "/Users/zoey.weng/.rustup/toolchains/nightly-x86_64-apple-darwin/lib/rustlib/x86_64-apple-darwin/lib/libunwind-77ff946ed091e776.rlib" "/Users/zoey.weng/.rustup/toolchains/nightly-x86_64-apple-darwin/lib/rustlib/x86_64-apple-darwin/lib/liballoc_system-5019a7c1f162c628.rlib" "/Users/zoey.weng/.rustup/toolchains/nightly-x86_64-apple-darwin/lib/rustlib/x86_64-apple-darwin/lib/liblibc-e10360ce0d79ef62.rlib" "/Users/zoey.weng/.rustup/toolchains/nightly-x86_64-apple-darwin/lib/rustlib/x86_64-apple-darwin/lib/liballoc-e51a1c9172064039.rlib" "/Users/zoey.weng/.rustup/toolchains/nightly-x86_64-apple-darwin/lib/rustlib/x86_64-apple-darwin/lib/libcore-877355077ec8f233.rlib" "/Users/zoey.weng/.rustup/toolchains/nightly-x86_64-apple-darwin/lib/rustlib/x86_64-apple-darwin/lib/libcompiler_builtins-b0eb581bdf96e971.rlib" "-lSystem" "-lresolv" "-lpthread" "-lc" "-lm"


  = note: ld: warning: URGENT: building for iOS simulator, but linking in object file (/Users/zoey.weng/.rustup/toolchains/nightly-x86_64-apple-darwin/lib/rustlib/x86_64-apple-darwin/lib/liballoc_jemalloc-1bc3e7256eaffb7f.rlib(jemalloc.pic.o)) built for OSX. Note: This will be an error in the future.


          ld: warning: object file (/Users/zoey.weng/.rustup/toolchains/nightly-x86_64-apple-darwin/lib/rustlib/x86_64-apple-darwin/lib/liballoc_jemalloc-1bc3e7256eaffb7f.rlib(jemalloc.pic.o)) was built for newer OSX version (10.7) than being linked (10.0)


          Undefined symbols for architecture x86_64:
            "_opendir$INODE64", referenced from:
                _macho_try_dsym in libstd-d9af9c9ee75d1d46.rlib(macho.o)
                _macho_add in libstd-d9af9c9ee75d1d46.rlib(macho.o)
            "_readdir$INODE64", referenced from:
                _macho_try_dsym in libstd-d9af9c9ee75d1d46.rlib(macho.o)
                _macho_add in libstd-d9af9c9ee75d1d46.rlib(macho.o)
          ld: symbol(s) not found for architecture x86_64
          clang: error: linker command failed with exit code 1 (use -v to see invocation)

This is my project demo https://github.com/piaojin/PJToDo, you can check out it to reduce the issues. ๐Ÿ˜œ

I need to build lib in my mac terminal for the first time. If I delete the target in the cargo I need to rebuild in my mac terminal again. But after that, I can build in Xcode well. So I need to build lib in my mac terminal if there are no libxxxxx.a in the target of cargo or the target has been deleted. This way works but not well. So if you have any other good way to solve this issues please tell me. Thank you!

TimNN commented

I've seen similar error in the past: rust-lang/rust#34617

This looks like an upstream issue with how jemalloc is built for distribution.

Potential work-arounds:

TimNN commented

Actually, disregard my previous comment. It looks like the issue is that cargo-lipo is being called from an XCode Build script or something. This can cause issues because XCode sets some environment variables. IIRC one of them says something like "build for ... (here: iOS Simulator)". The issue is, however, that cargo first wants to compile a build script for the host platform, not the simulator.

So unsetting certain environment variables before calling cargo-lipo should fix the isssue. I may have something like this in a private project, I can take a look later.

A general fix for this may be possible in cargo-lipo, cargo or rustc, but I don't know without further investigation.

TimNN commented

I have the following in a wrapper script of mine:

# Causes problems when compiling build dependencies / scripts
unset IPHONEOS_DEPLOYMENT_TARGET
unset $(env | grep '^SDK' | cut -d'=' -f1)

Let me know if adding that to your scripts works.

@TimNN It works fine after adding the above scripts. So nice! Thanks for your help.

This also worked for me. Would be nice to have a more general solution. ๐Ÿ˜„

In fact, just setting the user defined setting SDKROOT to empty in the Xcode target was enough to make it build. DIdn't have to touch IPHONEOS_DEPLOYMENT_TARGET ๐Ÿ‘