How to install Rust on Macbook: linker?

I'm trying to install Rust on my Macbook, which doesn't have linker (or any C compiler).

Rustup successfully produces "Rust is installed now. Great!"

The Installation - The Rust Programming Language mentions that the linker is required, but I didn't do any C development on this machine.

Is there a way to install a linker for Rust on a Macbook? Xcode can't be installed.

What's the output of ld --version on your system? How about cc --version?

Both of them say "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." I can't install Xcode and looking for another approach. A 3rd party linker?

You don't need all of Xcode; just the command-line tools:

xcode-select --install
1 Like

It says "xcode-select: note: install requested for command line developer tools" and opens the same dialog with Xcode installation.

You probably should download Xcode on your mac

I can't install Xcode on this computer. Are there any ways to get a linker working for the Rust installation or this is a tool which is unavoidable with 3rd party replacements?

Are you able to use a package manager like Homebrew? brew install llvm would probably be the simplest way of getting a non-Xcode LLVM toolchain (including a linker and C compiler) on your system—otherwise you might have to build one from source.

Here is what I'm getting:

$ brew install llvm
xcode-select: error: unable to get active developer directory, use sudo xcode-select --switch path/to/Xcode.app to set one (or see man xcode-select)
Error: The following formula:
llvm
cannot be installed as a a binary package and must be built from source.
To continue, you must install Xcode from the App Store,
or the CLT by running:
xcode-select --install
$

Can I build Rust from source on this computer (which doesn't have C)? Can I build non-Xcode toolchain from source? How?

That's strange, because the Homebrew page says the llvm formula supports binary installation (for which you shouldn't need Xcode). I don't know what might be causing the problem here. Can you brew install gcc instead?

Same thing.

$ brew install gcc
xcode-select: error: unable to get active developer directory, use sudo xcode-select --switch path/to/Xcode.app to set one (or see man xcode-select)
Error: The following formula:
gcc
cannot be installed as a a binary package and must be built from source.
To continue, you must install Xcode from the App Store,
or the CLT by running:
xcode-select --install
$

You could try downloading clang+llvm-12.0.0-x86_64-apple-darwin.tar.xz (assuming this is an Intel Mac) from LLVM's GitHub releases and copying the executables to somewhere that's on your PATH. You might also have to copy some shared objects from the lib/ directory, I'm not sure.

Thank you. I've added my PATH with /bin directory from the untarred archive. After that (I didn't edit symlinks) I have

$ which cc
/usr/bin/cc
$ ls -l /usr/bin/cc
/usr/bin/cc -> clang
$ which clang
< path to untarred directory >/bin/clang
$ clang --version
clang version 12.0.0
Target: x86_64-apple-darwin17.5.0
Thread model: posix
InstalledDir: < path to untarred directory >/bin
$ cc --version

still returns the same "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."

Maybe this is a silly question, but why can't you install Xcode on it?

It's a long story. It's also interesting by itself - if it is possible - at all - to install Rust on OS X without Xcode or not.

It certainly is possible, I'm using Rust on a Mac without Xcode. The "Xcode" command line tools really doesn't have much to do with Xcode, it's just a standard C, C++ and Objective-C toolchain based on Clang and LLVM. (Yeah, it probably does contain some Apple-specific CLI tools, but the point is that you don't need those in order to install Rust.)

It's possible to use Rust without Xcode in the same way it's possible to eat a soup with a fork.

In practice, Rust requires developer tools that Apple bundles with Xcode. You can make a DIY developer tools yourself, basically rebuilding everything that Xcode ships, but it's going to cause you a lot of headaches. Cargo dependencies that rely on a C compiler or Apple's system headers will cause problems too.

Homebrew will also complain about lack of Xcode tools. A Mac without Xcode is not suitable for development.

If your macOS is broken and can't have Xcode, reinstall. If you're forbidden from using Xcode by some Enterprise Corporate Policy, complain about it, because it's incredibly counter-productive (or change jobs, if you can).

If all else fails, maybe get a virtual machine and use Linux version of Rust? It will still need a linker, etc. but Linux distros come with build-essentials packages.

4 Likes