Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Detect linkage error when xcode-select --install hasn't been run #84534

Closed
estebank opened this issue Apr 25, 2021 · 5 comments · Fixed by #139010
Closed

Detect linkage error when xcode-select --install hasn't been run #84534

estebank opened this issue Apr 25, 2021 · 5 comments · Fixed by #139010
Labels
A-diagnostics Area: Messages for errors, warnings, and lints A-linkage Area: linking into static, shared libraries and binaries D-newcomer-roadblock Diagnostics: Confusing error or lint; hard to understand for new users. O-macos Operating system: macOS T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@estebank
Copy link
Contributor

When trying to run rustc for the first time on MacOS X, you might encounter this error message:

error: linking with cc failed: exit code: 1
|
= note:

"cc"
"-m64"
"-arch"
"x86_64"

"-L"
"/Users/z/.rustup/toolchains/stable-x86_64-apple-darwin/lib/rustlib/x86_64-apple-darwin/lib"
"main.main.7rcbfp3g-cgu.0.rcgu.o"
"main.main.7rcbfp3g-cgu.1.rcgu.o"
"main.main.7rcbfp3g-cgu.2.rcgu.o"
"main.main.7rcbfp3g-cgu.3.rcgu.o"
"main.main.7rcbfp3g-cgu.4.rcgu.o"
"main.main.7rcbfp3g-cgu.5.rcgu.o"
"main.main.7rcbfp3g-cgu.6.rcgu.o"
"main.main.7rcbfp3g-cgu.7.rcgu.o"

"-o"
"main"
"main.4s37gsrti678ik8u.rcgu.o"
"-Wl,-dead_strip"
"-nodefaultlibs"

"-L"
"/Users/z/.rustup/toolchains/stable-x86_64-apple-darwin/lib/rustlib/x86_64-apple-darwin/lib"
"/Users/z/.rustup/toolchains/stable-x86_64-apple-darwin/lib/rustlib/x86_64-apple-darwin/lib/libstd-349f286494d73b18.rlib"
"/Users/z/.rustup/toolchains/stable-x86_64-apple-darwin/lib/rustlib/x86_64-apple-darwin/lib/libpanic_unwind-0c9fcc24a503d489.rlib"
"/Users/z/.rustup/toolchains/stable-x86_64-apple-darwin/lib/rustlib/x86_64-apple-darwin/lib/libobject-70419d92d1ba4b1d.rlib"
"/Users/z/.rustup/toolchains/stable-x86_64-apple-darwin/lib/rustlib/x86_64-apple-darwin/lib/libaddr2line-65e88774cb68bd46.rlib"
"/Users/z/.rustup/toolchains/stable-x86_64-apple-darwin/lib/rustlib/x86_64-apple-darwin/lib/libgimli-3849b3781a19a398.rlib"
"/Users/z/.rustup/toolchains/stable-x86_64-apple-darwin/lib/rustlib/x86_64-apple-darwin/lib/librustc_demangle-0dbb03fa66ca6d84.rlib"
"/Users/z/.rustup/toolchains/stable-x86_64-apple-darwin/lib/rustlib/x86_64-apple-darwin/lib/libhashbrown-65edff8661311c85.rlib"
"/Users/z/.rustup/toolchains/stable-x86_64-apple-darwin/lib/rustlib/x86_64-apple-darwin/lib/librustc_std_workspace_alloc-599e707cd7ee7216.rlib"
"/Users/z/.rustup/toolchains/stable-x86_64-apple-darwin/lib/rustlib/x86_64-apple-darwin/lib/libunwind-40cb05f6c516791a.rlib"
"/Users/z/.rustup/toolchains/stable-x86_64-apple-darwin/lib/rustlib/x86_64-apple-darwin/lib/libcfg_if-7a0a923a4d37a048.rlib"
"/Users/z/.rustup/toolchains/stable-x86_64-apple-darwin/lib/rustlib/x86_64-apple-darwin/lib/liblibc-7e047938e88325ef.rlib"
"/Users/z/.rustup/toolchains/stable-x86_64-apple-darwin/lib/rustlib/x86_64-apple-darwin/lib/liballoc-02542d835be27c0f.rlib"
"/Users/z/.rustup/toolchains/stable-x86_64-apple-darwin/lib/rustlib/x86_64-apple-darwin/lib/librustc_std_workspace_core-63712b18a1365082.rlib"
"/Users/z/.rustup/toolchains/stable-x86_64-apple-darwin/lib/rustlib/x86_64-apple-darwin/lib/libcore-1196a2a060497e71.rlib"
"/Users/z/.rustup/toolchains/stable-x86_64-apple-darwin/lib/rustlib/x86_64-apple-darwin/lib/libcompiler_builtins-10db70d883838cbc.rlib"

"-lSystem"
"-lresolv"
"-lc"
"-lm"

= note: xcrun: error: invalid active developer path (/Library/Developer/CommandLineTools), missing xcrun at: /Library/Developer/CommandLineTools/usr/bin/xcrun

This happens if you haven't installed the Developer Command Line Tools with xcode-select --install.

We should detect the error output message "missing xcrun" and when it happens, emit a more targeted, friendlier error explaining what happened to the user.

Taken from https://users.rust-lang.org/t/error-compiling-my-first-basic-rust-program/58872

@estebank estebank added A-linkage Area: linking into static, shared libraries and binaries O-macos Operating system: macOS A-diagnostics Area: Messages for errors, warnings, and lints T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. D-newcomer-roadblock Diagnostics: Confusing error or lint; hard to understand for new users. labels Apr 25, 2021
@nagisa
Copy link
Member

nagisa commented Apr 25, 2021

From my memory, I recall seeing a MacOS pop-up a suggestion to install the XCode if I needed the commands in question. Is that not a thing anymore?

@estebank
Copy link
Contributor Author

Changes on the MacOS side might have made that suggestion stop being detected.

@ehuss
Copy link
Contributor

ehuss commented Apr 25, 2021

It would be good to know which version of macOS that came from. On Catalina (10.15) the error is:

= note: xcode-select: note: no developer tools were found at '/Applications/Xcode.app', requesting install. Choose an option in the dialog to download the command line developer tools.

And a GUI dialog box pops up to install the tools.

Perhaps Big Sur (11) is different, or maybe they are on an M1 that has strange behavior.

@estebank
Copy link
Contributor Author

Asked the original reporter to update this ticket.

@smrjdhv
Copy link

smrjdhv commented Apr 28, 2021

Here are my machine specs:
MacBook Pro (15-inch, 2017)
2.9 GHz Quad-Core Intel Core i7
16 GB 2133 MHz LPDDR3
Intel HD Graphics 630 1536 MB

macOS Big Sur, version 11.2.1

PFA screenshots of installation process followed.
rust Install 1
rust Install 2

jhpratt added a commit to jhpratt/rust that referenced this issue Mar 27, 2025
…eywiser

Improve `xcrun` error handling

The compiler invokes `xcrun` on macOS when linking Apple targets, to find the Xcode SDK which contain all the necessary linker stubs. The error messages that `xcrun` outputs aren't always that great though, so this PR tries to improve that by providing extra context when an error occurs.

Fixes rust-lang#56829.
Fixes rust-lang#84534.
Part of rust-lang#129432.
See also the alternative rust-lang#131433.

Tested on:
- `x86_64-apple-darwin`, MacBook Pro running Mac OS X 10.12.6
    - With no tooling installed
    - With Xcode 9.2
    - With Xcode 9.2 Commandline Tools
- `aarch64-apple-darwin`, MacBook M2 Pro running macOS 14.7.4
    - With Xcode 13.4.1
    - With Xcode 16.2
    - Inside `nix-shell -p xcbuild` (nixpkgs' `xcrun` shim)
- `aarch64-apple-darwin`, VM running macOS 15.3.1
    - With no tooling installed
    - With Xcode 16.2 Commandline Tools

`@rustbot` label O-apple
r? compiler
CC `@BlackHoleFox` `@thomcc`
@bors bors closed this as completed in 0b40e6e Mar 28, 2025
rust-timer added a commit to rust-lang-ci/rust that referenced this issue Mar 28, 2025
Rollup merge of rust-lang#139010 - madsmtm:parse-xcrun-better, r=wesleywiser

Improve `xcrun` error handling

The compiler invokes `xcrun` on macOS when linking Apple targets, to find the Xcode SDK which contain all the necessary linker stubs. The error messages that `xcrun` outputs aren't always that great though, so this PR tries to improve that by providing extra context when an error occurs.

Fixes rust-lang#56829.
Fixes rust-lang#84534.
Part of rust-lang#129432.
See also the alternative rust-lang#131433.

Tested on:
- `x86_64-apple-darwin`, MacBook Pro running Mac OS X 10.12.6
    - With no tooling installed
    - With Xcode 9.2
    - With Xcode 9.2 Commandline Tools
- `aarch64-apple-darwin`, MacBook M2 Pro running macOS 14.7.4
    - With Xcode 13.4.1
    - With Xcode 16.2
    - Inside `nix-shell -p xcbuild` (nixpkgs' `xcrun` shim)
- `aarch64-apple-darwin`, VM running macOS 15.3.1
    - With no tooling installed
    - With Xcode 16.2 Commandline Tools

``@rustbot`` label O-apple
r? compiler
CC ``@BlackHoleFox`` ``@thomcc``
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-diagnostics Area: Messages for errors, warnings, and lints A-linkage Area: linking into static, shared libraries and binaries D-newcomer-roadblock Diagnostics: Confusing error or lint; hard to understand for new users. O-macos Operating system: macOS T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
4 participants