clang-7: error: linker command failed with exit code 1 for macOS Big Sur
This has been challenging, but here are the steps I used compile R packages from source on MacOS Big Sur:
- 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
- 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
- If you already have gcc & llvm installed via Homebrew:
brew cleanup
brew update
brew upgrade
brew reinstall gcc
brew reinstall llvm
- 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
- Edit your
~/.R/Makevars
file (if you don't have a file calledMakevars
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
- 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++
clang: error: linker command failed with exit code 1 when running fishchips on macOS
I believe I found the solution fix. It seems as if deleting OMPFLAG was all that was needed to run.
error: linking with `cc` failed: exit code: 1
From your command rustc test1.rs
the compiler infers the name of the executable should be test1
. The linker tries to open this file so it can write the executable but fails with errno=21
whose stringified version is "Is a directory".
This suggests you have a directory in your working directory called test1
which is causing a conflict.
Big Sur clang invalid version error due to MACOSX_DEPLOYMENT_TARGET
Figure out the issue on my end.
Previously I had installed XCode
from the App Store (11.7) and set its SDKs as my default:
sudo xcode-select --switch /Applications/Xcode.app/
However, it seems this come with an unsupported version of clang
:
λ clang --version
Apple clang version 11.0.3 (clang-1103.0.32.62)
Target: x86_64-apple-darwin20.1.0
Thread model: posix
InstalledDir: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin
Setting the xcode-select
to the latest version via:
sudo xcode-select --switch /Library/Developer/CommandLineTools
EDIT (11/15/2020)
You might receive an error when attempting the above change:
xcode-select: error: invalid developer directory '/Library/Developer/CommandLineTools'
To fix this, you must install the latest Command Line Tools from the official Apple website here. At the time of writting this edit, I installed the Command Line Tools for Xcode 12.3 beta.
Changes clang
to a working version:
λ clang --version
Apple clang version 12.0.0 (clang-1200.0.32.2)
Target: x86_64-apple-darwin20.1.0
Thread model: posix
InstalledDir: /Library/Developer/CommandLineTools/usr/bin
The built-in Big Sur SDK is version 10.15
, which seems to work without an issue:
λ ls /Library/Developer/CommandLineTools/SDKs
MacOSX.sdk MacOSX10.15.sdk
After the switch, multidict
was installed successfully.
λ pip install multidict
Collecting multidict
Downloading multidict-4.7.6-cp38-cp38-macosx_10_14_x86_64.whl (48 kB)
|████████████████████████████████| 48 kB 589 kB/s
Installing collected packages: multidict
Successfully installed multidict-4.7.6
Further investigation seems to indicate this is a design choice by Apple (source):
Therefore, ensuring your SDK is the default out-of-the-box as opposed to XCode's new SDK should be enough for the system to switch context when needed (and seems to work fine with pip
+clang
).
Issues installing RcppMP in MacOS
This was a bit more complicated than I thought; this package requires mpfr, gmp and the very-similarly-named mpfrc++. The steps that worked for me are:
Install gmp and mpfr via homebrew
Download and unzip "mpfrc++-3.6.8.zip" from
http://www.holoborodko.com/pavel/mpfr/#downloadCopy the mpreal header file ("mpreal.h") to
/usr/local/include (sudo cp ./mpreal.h /usr/local/include/
) or, in your case, perhapssudo cp ./mpreal.h /usr/local/opt/llvm/include
would make more senseInstall/compile RcppMP
(remotes::install_github("Thell/RcppMP",dependencies = TRUE)
)
I got some warnings but no errors, and the package loaded (library(RcppMP)
), so I'm relatively confident it installed successfully. If you find otherwise, please let me know and I'll look into it further.
Related Topics
Using Regex in R to Find Strings as Whole Words (But Not Strings as Part of Words)
Levels≪-'( What Sorcery Is This
Plot Multiple Lines (Data Series) Each With Unique Color in R
How to Calculate Mean/Median Per Group in a Dataframe in R
Proper/Fastest Way to Reshape a Data.Table
Putting Mathematical Symbols and Subscripts Mixed With Regular Letters
Remove Extra Legends in Ggplot2
Multiple Use of the Positional '$' Operator to Update Nested Arrays
Melt/Reshape in Excel Using Vba
How to Set Up Conda-Installed R For Use With Rstudio
How to Uninstall R and Rstudio With All Packages, Settings and Everything Else
How to Assign Values to Dynamic Names Variables
Extract the First 2 Characters in a String
Sample N Random Rows Per Group in a Dataframe