Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

clang-7: error: linker command failed with exit code 1 for macOS Big Sur

Installing R packages that need compiling in macOS is broken since Big Sur. Here is such an example.

> install.packages('nlme')

  There is a binary version available but the source version is later:
      binary  source needs_compilation
nlme 3.1-150 3.1-151              TRUE

Do you want to install from sources the package which needs compilation? (Yes/no/cancel) Yes
installing the source package ‘nlme’

trying URL 'https://cran.rstudio.com/src/contrib/nlme_3.1-151.tar.gz'
Content type 'application/x-gzip' length 805592 bytes (786 KB)
==================================================
downloaded 786 KB

* installing *source* package ‘nlme’ ...
** package ‘nlme’ successfully unpacked and MD5 sums checked
** using staged installation
** libs
"gfortran-4.8" -fno-optimize-sibling-calls  -fPIC  -Wall -g -O2  -c chol.f -o chol.o
gfortran-4.8: warning: couldn’t understand kern.osversion ‘20.1.0
clang -mmacosx-version-min=10.13 -I"/Library/Frameworks/R.framework/Resources/include" -DNDEBUG   -I/usr/local/include   -fPIC  -Wall -g -O2  -c corStruct.c -o corStruct.o
clang -mmacosx-version-min=10.13 -I"/Library/Frameworks/R.framework/Resources/include" -DNDEBUG   -I/usr/local/include   -fPIC  -Wall -g -O2  -c gnls.c -o gnls.o
clang -mmacosx-version-min=10.13 -I"/Library/Frameworks/R.framework/Resources/include" -DNDEBUG   -I/usr/local/include   -fPIC  -Wall -g -O2  -c init.c -o init.o
clang -mmacosx-version-min=10.13 -I"/Library/Frameworks/R.framework/Resources/include" -DNDEBUG   -I/usr/local/include   -fPIC  -Wall -g -O2  -c matrix.c -o matrix.o
clang -mmacosx-version-min=10.13 -I"/Library/Frameworks/R.framework/Resources/include" -DNDEBUG   -I/usr/local/include   -fPIC  -Wall -g -O2  -c nlOptimizer.c -o nlOptimizer.o
clang -mmacosx-version-min=10.13 -I"/Library/Frameworks/R.framework/Resources/include" -DNDEBUG   -I/usr/local/include   -fPIC  -Wall -g -O2  -c nlme.c -o nlme.o
clang -mmacosx-version-min=10.13 -I"/Library/Frameworks/R.framework/Resources/include" -DNDEBUG   -I/usr/local/include   -fPIC  -Wall -g -O2  -c nlmefit.c -o nlmefit.o
clang -mmacosx-version-min=10.13 -I"/Library/Frameworks/R.framework/Resources/include" -DNDEBUG   -I/usr/local/include   -fPIC  -Wall -g -O2  -c pdMat.c -o pdMat.o
clang -mmacosx-version-min=10.13 -I"/Library/Frameworks/R.framework/Resources/include" -DNDEBUG   -I/usr/local/include   -fPIC  -Wall -g -O2  -c pythag.c -o pythag.o
"gfortran-4.8" -fno-optimize-sibling-calls  -fPIC  -Wall -g -O2  -c rs.f -o rs.o
gfortran-4.8: warning: couldn’t understand kern.osversion ‘20.1.0
clang -mmacosx-version-min=10.13 -dynamiclib -Wl,-headerpad_max_install_names -undefined dynamic_lookup -single_module -multiply_defined suppress -L/Library/Frameworks/R.framework/Resources/lib -L/usr/local/lib -o nlme.so chol.o corStruct.o gnls.o init.o matrix.o nlOptimizer.o nlme.o nlmefit.o pdMat.o pythag.o rs.o  -F/Library/Frameworks/R.framework/.. -framework R -Wl,-framework -Wl,CoreFoundation
ld: framework not found CoreFoundation
clang-7: error: linker command failed with exit code 1 (use -v to see invocation)
make: *** [nlme.so] Error 1
ERROR: compilation failed for package ‘nlme’
* removing ‘/Library/Frameworks/R.framework/Versions/4.0/Resources/library/nlme’
* restoring previous ‘/Library/Frameworks/R.framework/Versions/4.0/Resources/library/nlme’
Warning in install.packages :
  installation of package ‘nlme’ had non-zero exit status

The downloaded source packages are in
    ‘/private/var/folders/_3/b8whcf8d1bb8w_lr2rrscb5m0000gp/T/RtmpWCjwfs/downloaded_packages’

I've tried reinstalling xcode and Command Line Tools and completed Brew update + upgrade. Any suggestions appreciated.

like image 628
geotheory Avatar asked Dec 11 '20 13:12

geotheory


People also ask

What is meant by linker command failed with exit code 1?

clang: error: linker command failed with exit code 1 (open frameworks) exitCode1. This means you have two files which have a function called "main" in them -- the compiler compiles all the code fine, but when it goes to link, it sees two object symbols that have the same name.

What linker does clang use?

Clang can be configured to use one of several different linkers: GNU ld. GNU gold. LLVM's lld.

How do I fix clang error linker command failed with exit code 1?

My iOS builds fail with "clang: error: linker command failed with exit code 1" Clang! The error could be caused by App Center building with the xcodeproj instead of the workspace. When adding CocoaPods to your project, you must switch to using the workspace when building in App Center.


1 Answers

This has been challenging, but here are the steps I used compile R packages from source on MacOS Big Sur:

  1. Reinstall xcode command line tools

(don't believe Software Update if it says 'up to date' - he lies - brew doctor said my version was actually old)

sudo rm -rf /Library/Developer/CommandLineTools
sudo xcode-select --install
  1. Install gcc & llvm via Homebrew (instructions for installing Homebrew) or, if you already have gcc/llvm installed, skip to the next step
# WARNING: This can take several hours
brew install gcc
brew install llvm
  1. If you already have gcc & llvm installed via Homebrew:
brew cleanup
brew update
brew upgrade
brew reinstall gcc
brew reinstall llvm
  1. Link some headers into /usr/local/include
sudo ln -s /Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include/* /usr/local/include/

# I believe you can safely ignore warnings like this:
#ln: /usr/local/include//tcl.h: File exists
#ln: /usr/local/include//tclDecls.h: File exists
#ln: /usr/local/include//tclPlatDecls.h: File exists
#ln: /usr/local/include//tclTomMath.h: File exists
#ln: /usr/local/include//tclTomMathDecls.h: File exists
#ln: /usr/local/include//tk.h: File exists
#ln: /usr/local/include//tkDecls.h: File exists
#ln: /usr/local/include//tkPlatDecls.h: File exists
  1. Edit your ~/.R/Makevars file (if you don't have a file called Makevars in your ~/.R/ directory, create it) and include only these lines:
FLIBS=-L/usr/local/gfortran/lib/gcc/x86_64-apple-darwin19/10.2.0 -L/usr/local/gfortran/lib -lgfortran -lquadmath -lm
CXX1X=/usr/local/gfortran/bin/g++
CXX98=/usr/local/gfortran/bin/g++
CXX11=/usr/local/gfortran/bin/g++
CXX14=/usr/local/gfortran/bin/g++
CXX17=/usr/local/gfortran/bin/g++

LLVM_LOC = /usr/local/opt/llvm
CC=/usr/local/gfortran/bin/gcc -fopenmp
CXX=/usr/local/gfortran/bin/g++ -fopenmp
CFLAGS=-g -O3 -Wall -pedantic -std=gnu99 -mtune=native -pipe
CXXFLAGS=-g -O3 -Wall -pedantic -std=c++11 -mtune=native -pipe
LDFLAGS=-L/usr/local/opt/gettext/lib -L$(LLVM_LOC)/lib -Wl,-rpath,$(LLVM_LOC)/lib
CPPFLAGS=-I/usr/local/opt/gettext/include -I$(LLVM_LOC)/include -I/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include
  1. Compile a package from source in R/Rstudio
# Compile the nlme package from source
install.packages("nlme", type = "source")

# To check whether openmp is enabled, compile data.table:
install.packages("data.table", type = "source")

Update (2022/04/05)

I had an error when updating "RcppAlgos" (couldn't find gmp.h or libgmp). I checked gmp was installed (brew install gmp), then added /usr/local/include to CPPFLAGS and /usr/local/lib to LDFLAGS in the ~/.R/Makevars file to solve the problem, i.e.

cat ~/.R/Makevars
LOC=/usr/local/gfortran
CC=$(LOC)/bin/gcc -fopenmp
CXX=$(LOC)/bin/g++ -fopenmp
CXX11 = $(LOC)/bin/g++ -fopenmp

CFLAGS=-g -O3 -Wall -pedantic -std=gnu99 -mtune=native -pipe
CXXFLAGS=-g -O3 -Wall -pedantic -std=c++11 -mtune=native -pipe
LDFLAGS=-L$(LOC)/lib -Wl,-rpath,$(LOC)/lib,-L/usr/local/lib
CPPFLAGS=-I$(LOC)/include -I/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include -I/usr/local/include

FLIBS=-L/usr/local/gfortran/lib/gcc/x86_64-apple-darwin19/10.2.0 -L/usr/local/gfortran/lib -lgfortran -lquadmath -lm
CXX1X=/usr/local/gfortran/bin/g++
CXX98=/usr/local/gfortran/bin/g++
CXX11=/usr/local/gfortran/bin/g++
CXX14=/usr/local/gfortran/bin/g++
CXX17=/usr/local/gfortran/bin/g++
like image 113
jared_mamrot Avatar answered Oct 21 '22 16:10

jared_mamrot