Skip to content

Linker errors when cross-compiling from Xcode on Big Sur #80817

@irh

Description

@irh

Hi all, invoking cargo build from Xcode on Big Sur currently fails when a crate needs to link against a system library from a build script, unless SDKROOT has been explicitly set to the path of the macOS SDK. Test project here.

When invoking cargo build from an Xcode build script, SDKROOT is set for the platform that's being built. #64254 made it so that SDKROOT gets un-set if the target platform doesn't match the host platform. This seems reasonable to me, but then I don't understand why there's now a difference in behaviour between Xcode and non-Xcode builds.

I logged a similiar issue for cargo-lipo, which has a different workaround of instead setting LIBRARY_PATH.

Activity

added
C-bugCategory: This is a bug.
on Jan 8, 2021
nfriedly

nfriedly commented on Dec 14, 2022

@nfriedly

My team has also been hitting this issue since macOS 11/Big Sur, and initially setting the LIBRARY_PATH and SDK_ROOT seemed to make it work, but after upgrading to macOS 14/Ventura, I (and apparently only I) started hitting this same issue again. I dug into it for a while and noticed this tidbit mentioning that Xcode's copy of ld behaves differently from the one in /usr/bin.

So, the final solution I settled on was undoing my LIBRARY_PATH and SDK_ROOT and instead resetting PATH to exclude all of the Xcode folders in my build script:

export PATH="/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin"

After that, rust builds seem to work reliably from both Xcode and the command line.

added 2 commits that reference this issue on Sep 14, 2024

Rollup merge of rust-lang#130334 - madsmtm:macos-sdkroot-ignore, r=ji…

55d5c32

Rollup merge of rust-lang#130334 - madsmtm:macos-sdkroot-ignore, r=ji…

73f684f
added a commit that references this issue on Sep 14, 2024
madsmtm

madsmtm commented on Oct 10, 2024

@madsmtm
Contributor

I can reproduce this with:

PATH="/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin:$PATH" rustc foo.rs

With the current nightly, it should work with -Clinker-flavor=ld, and #131477 will make this work with the default linker.

10 remaining items

Loading
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-crossArea: Cross compilationC-bugCategory: This is a bug.O-macosOperating system: macOS

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

      Participants

      @nfriedly@irh@madsmtm@camelid

      Issue actions

        Linker errors when cross-compiling from Xcode on Big Sur · Issue #80817 · rust-lang/rust