Warm tip: This article is reproduced from serverfault.com, please click

"ld: library not found for -lSystem" when installing homebrew ruby on Big Sur

发布于 2020-11-21 10:49:19

Installing OS11 Big Sur made it so my ruby installation no longer works, so I'm trying to reinstall it. I've installed rbenv from the instructions here, and the rbenv-doctor script runs indicating no problems. But when I try to run rbenv install 2.7.2 I get an error related to my compiler setup:

% rbenv install 2.7.2
Downloading ruby-2.7.2.tar.bz2...
-> https://cache.ruby-lang.org/pub/ruby/2.7/ruby-2.7.2.tar.bz2
Installing ruby-2.7.2...
ruby-build: using readline from homebrew

BUILD FAILED (macOS 11.0.1 using ruby-build 20201005)

Inspect or clean up the working tree at /var/folders/yn/wzkl_t8567l9pvwhp0wsm40w0000gn/T/ruby-build.20201121103616.80606.FFBFEn
Results logged to /var/folders/yn/wzkl_t8567l9pvwhp0wsm40w0000gn/T/ruby-build.20201121103616.80606.log

Last 10 log lines:
tool/config.guess already exists
tool/config.sub already exists
checking build system type... x86_64-apple-darwin20.1.0
checking host system type... x86_64-apple-darwin20.1.0
checking target system type... x86_64-apple-darwin20.1.0
checking whether the C compiler works... no
configure: error: in `/var/folders/yn/wzkl_t8567l9pvwhp0wsm40w0000gn/T/ruby-build.20201121103616.80606.FFBFEn/ruby-2.7.2':
configure: error: C compiler cannot create executables
See `config.log' for more details
make: *** No targets specified and no makefile found.  Stop.

The corresponding config.log is quite long, of course, but relevant lines are:

configure:3017: checking for ruby
configure:3035: found /usr/bin/ruby
configure:3048: result: /usr/bin/ruby
configure:3121: checking build system type
configure:3135: result: x86_64-apple-darwin20.1.0
configure:3223: checking host system type
configure:3236: result: x86_64-apple-darwin20.1.0
configure:3256: checking target system type
configure:3269: result: x86_64-apple-darwin20.1.0
configure:4016: checking for C compiler version
configure:4025: clang --version >&5
clang version 6.0.0 (tags/RELEASE_600/final)
Target: x86_64-apple-darwin20.1.0
Thread model: posix
InstalledDir: /usr/local/clang6/bin
configure:4036: $? = 0
configure:4025: clang -v >&5
clang version 6.0.0 (tags/RELEASE_600/final)
Target: x86_64-apple-darwin20.1.0
Thread model: posix
InstalledDir: /usr/local/clang6/bin
configure:4036: $? = 0
configure:4025: clang -V >&5
clang-6.0: error: argument to '-V' is missing (expected 1 value)
clang-6.0: error: no input files
configure:4036: $? = 1
configure:4025: clang -qversion >&5
clang-6.0: error: unknown argument: '-qversion'
clang-6.0: error: no input files
configure:4036: $? = 1
configure:4056: checking whether the C compiler works
configure:4078: clang  -I/Users/richard/.rbenv/versions/2.7.2/include -I/usr/local/opt/readline/include -L/Users/richard/.rbenv/versions/2.7.2/lib -L/usr/local/opt/readline/lib conftest.c  >&5
ld: library not found for -lSystem
clang-6.0: error: linker command failed with exit code 1 (use -v to see invocation)
configure:4082: $? = 1
configure:4120: result: no
configure: failed program was:
| /* confdefs.h */
| #define PACKAGE_NAME ""
| #define PACKAGE_TARNAME ""
| #define PACKAGE_VERSION ""
| #define PACKAGE_STRING ""
| #define PACKAGE_BUGREPORT ""
| #define PACKAGE_URL ""
| /* end confdefs.h.  */
| 
| int
| main ()
| {
| 
|   ;
|   return 0;
| }
configure:4125: error: in `/var/folders/yn/wzkl_t8567l9pvwhp0wsm40w0000gn/T/ruby-build.20201121101556.78734.11rqwy/ruby-2.7.2':
configure:4127: error: C compiler cannot create executables
See `config.log' for more details

The (main?) problem appears to be the error:

ld: library not found for -lSystem

...but the errors before it seem to imply that the configure script doesn't understand the command line options...?

Here are some relevant details about my setup:

XCode command line tools:

% pkgutil --pkg-info=com.apple.pkg.CLTools_Executables | grep version
version: 12.2.0.0.1.1604076827

gcc:

% which gcc
/usr/bin/gcc
% gcc -v
Configured with: --prefix=/Applications/Xcode.app/Contents/Developer/usr --with-gxx-include-dir=/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/include/c++/4.2.1
Apple clang version 12.0.0 (clang-1200.0.32.27)
Target: x86_64-apple-darwin20.1.0
Thread model: posix
InstalledDir: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin

clang:

% which clang
/usr/local/clang6/bin/clang
% clang -v
clang version 6.0.0 (tags/RELEASE_600/final)
Target: x86_64-apple-darwin20.1.0
Thread model: posix
InstalledDir: /usr/local/clang6/bin

I also have the following in my .zprofile, in order to fix the problem that it wasn't finding the necessary header files before:

export CPATH="/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include"

Thanks in advance for any insight.

Questioner
richarddmorey
Viewed
0
anothermh 2020-12-03 15:12:02

The problem appears to be that you're using clang6 (probably from https://cran.r-project.org/bin/macosx/tools/) instead of the version of clang that ships with the Xcode Command Line Tools. You need Apple's version of clang.

Verify that you have installed the CLT with sudo xcode-select --install. Once they're installed verify that /usr/bin/clang -v returns something like Apple clang version 12. Now modify your $PATH and retry:

export PATH=/usr/bin:$PATH
rbenv install 2.7.2

Or use whatever other shell trick you prefer to get the Apple version of clang to be used by rbenv, then retry the installation.