簡體   English   中英

在 R 中安裝 stringi 時“C 編譯器無法創建可執行文件”

[英]"C compiler cannot create executables" when installing stringi in R

我經常從源代碼安裝 R 包,並且需要一個正確配置的~/.R/Makevars來執行此操作。 我希望能夠使用 OpenMP,所以我復制了我在網上找到的Makevars 我的Makevars最終是這樣的:

OPT_LOC = $(HOME)/homebrew/opt
LLVM_LOC = $(OPT_LOC)/llvm
CC=$(LLVM_LOC)/bin/clang
CXX=$(LLVM_LOC)/bin/clang++

# CFLAGS and CXXFLAGS *with* -fopenmp
CFLAGS=-fopenmp -g -O3 -Wall -pedantic -std=gnu99 -mtune=native -pipe
CXXFLAGS=-fopenmp -g -O3 -Wall -pedantic -std=c++11 -mtune=native -pipe

# CFLAGS and CXXFLAGS *without* -fopenmp
# (sometimes the package install process fails if -fopenmp is present)
# CFLAGS=-g -O3 -Wall -pedantic -std=gnu99 -mtune=native -pipe
# CXXFLAGS=-g -O3 -Wall -pedantic -std=c++11 -mtune=native -pipe

LDFLAGS=-L$(OPT_LOC)/gettext/lib -L$(LLVM_LOC)/lib -Wl,-rpath,$(LLVM_LOC)/lib
CPPFLAGS=-I$(OPT_LOC)/gettext/include -I$(LLVM_LOC)/include

我再也找不到我的版本的原始來源,但它與這個類似。

我的Makevars工作得很好,除了一些包,比如 stringi。 這些軟件包抱怨“C 編譯器無法創建可執行文件” 我發現如果我從CFLAGSCXXFLAGS刪除-fopenmp ,這個錯誤通常會消失。 如您所見,我已經設置了Makevars因此我可以輕松地在使用-fopenmp和不使用它的配置之間來回切換。

我的解決方法工作正常,就像上面鏈接的 SO 帖子中“完全刪除Makevars ”的解決方法一樣。 但是沒有更好的方法嗎? 令人討厭的是,由於這些討厭-fopenmp標志的依賴項,我無法期望軟件包安裝成功,而刪除該標志意味着我可能會在某些軟件包安裝中錯過 OpenMP。

如果您使用 gcc 而不是 clang,您應該能夠在啟用 openMP 的情況下安裝 stringi。 我已經測試了許多不同的解決方案,並最終想出了以下步驟,以使用-fopenmp標志(intel macOS Big Sur)從源代碼成功安裝 stringi:

  1. 重新安裝 xcode 命令行工具(不要相信軟件更新,如果它說“最新” - 他撒謊 - brew doctor說我的版本實際上很舊)
sudo rm -rf /Library/Developer/CommandLineTools
sudo xcode-select --install
  1. 通過 Homebrew 安裝 gcc 和 llvm(安裝 Homebrew 的說明),或者,如果您已經安裝了 gcc/llvm,請跳到下一步
# WARNING: This can take several hours
brew install gcc
brew install llvm
  1. 如果您已經通過 Homebrew 安裝了 gcc 和 llvm:
brew cleanup
brew update
brew upgrade
brew reinstall gcc
brew reinstall llvm
  1. 將一些頭文件鏈接到 /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. 編輯您的~/.R/Makevars文件(如果您的~/.R/目錄中沒有名為Makevars的文件,請創建它)並僅包含以下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
CPPFLAGS=-I$(LOC)/include -I/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/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++
  1. 在 R/Rstudio 中從源代碼編譯包
# Test if openMP is actually enabled
install.packages("data.table", type = "source")
# (loading data.table will tell you if it was successful)

# Compile the stringi package from source
install.packages("stringi", type = "source")

注意一些用戶評論說他們必須安裝一個“新鮮的”gfortran(例如https://github.com/fxcoudert/gfortran-for-macOS/releases/tag/10.2-bigsur-intel )才能成功編譯軟件包,還有其他人已經評論說他們不需要 llvm,但這些步驟似乎在大多數情況下都有效。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM