【问题标题】:Cannot install rJava from source as "C Compiler works ... no"无法从源代码安装 rJava,因为“C 编译器可以工作......不”
【发布时间】:2017-04-26 11:10:18
【问题描述】:

根据 SE 上的 much of the advice 关于让 Mac OS Sierra 10.12.4 很好地与 rJava 配合使用,建议建议从源代码安装。

但是,当我尝试运行 install.packages("rJava", type = "source") 时,我得到如下输出:

> install.packages("rJava", type = "source")
trying URL 'https://cran.rstudio.com/src/contrib/rJava_0.9-8.tar.gz'
Content type 'application/x-gzip' length 656615 bytes (641 KB)
==================================================
downloaded 641 KB

* installing *source* package ‘rJava’ ...
** package ‘rJava’ successfully unpacked and MD5 sums checked
checking for gcc... /usr/local/opt/llvm/bin/clang -fopenmp
checking whether the C compiler works... no
configure: error: in `/private/var/folders/lj/4s8lnxmj4_q8h65zk705k6dr0000gn/T/Rtmp4BrRQs/R.INSTALLd1278e3aab0/rJava':
configure: error: C compiler cannot create executables
See `config.log' for more details
ERROR: configuration failed for package ‘rJava’
* removing ‘/Library/Frameworks/R.framework/Versions/3.3/Resources/library/rJava’
Warning in install.packages :
  installation of package ‘rJava’ had non-zero exit status

The downloaded source packages are in
    ‘/private/var/folders/lj/4s8lnxmj4_q8h65zk705k6dr0000gn/T/RtmpFhnj89/downloaded_packages’

我尝试使用 brew 更新 gcc 和 gfortran,还修改了我的 makeconf as specified in answers here 并安装了 xcode。

更新:我相信我已经通过 clang 安装了 openmp,它是通过 llvm 安装的。

更新 2:根据 hrbrmstrs 的评论,他在 ~/.R/Makevars 的文件与我的有很大不同。我的假设是默认值:

CC=/usr/local/opt/llvm/bin/clang -fopenmp
CXX=/usr/local/opt/llvm/bin/clang++
LDFLAGS=-L/usr/local/opt/gettext/lib -L/usr/local/opt/llvm/lib
CPPFLAGS=-I/usr/local/opt/gettext/include -I/usr/local/opt/llvm/include

他们是:

# shell

sudo ln -f -s $(/usr/libexec/java_home)/jre/lib/server/libjvm.dylib /usr/local/lib

# ~/.R/Makevars
F77 = /usr/local/gfortran/bin/gfortran
FC = /usr/local/gfortran/bin/gfortran
FLIBS = -L/usr/local/gfortran/lib/gcc/x86_64-apple-darwin15/6.1.0 -L/usr/local/gfortran/lib -lgfortran -lquadmath -lm
CC=ccache /usr/local/opt/gcc/bin/gcc-6 -Wunused-argument
CXX=ccache /usr/local/opt/gcc/bin/g++-6 -Wunused-argument
CXX1X=ccache /usr/local/opt/gcc/bin/g++-6
SHLIB_CXXLD=ccache /usr/local/opt/gcc/bin/g++-6
CCACHE_CPP=yes
CCACHE_CPP2=yes
MAKE=make -j8

有空as a gist too

install.packages("rJava, type = "source") 的输出现在是

> install.packages("rJava", type = "source")
trying URL 'https://cran.rstudio.com/src/contrib/rJava_0.9-8.tar.gz'
Content type 'application/x-gzip' length 656615 bytes (641 KB)
==================================================
downloaded 641 KB

* installing *source* package ‘rJava’ ...
** package ‘rJava’ successfully unpacked and MD5 sums checked
/Users/davidparr/.R/Makevars:10: *** missing separator.  Stop.
/Users/davidparr/.R/Makevars:10: *** missing separator.  Stop.
checking for gcc... gcc
checking whether the C compiler works... yes
checking for C compiler default output file name... a.out
checking for suffix of executables... 
checking whether we are cross compiling... no
checking for suffix of object files... o
checking whether we are using the GNU C compiler... yes
checking whether gcc accepts -g... yes
checking for gcc option to accept ISO C89... none needed
checking how to run the C preprocessor... gcc -E
checking for grep that handles long lines and -e... /usr/bin/grep
checking for egrep... /usr/bin/grep -E
checking for ANSI C header files... yes
checking for sys/wait.h that is POSIX.1 compatible... yes
checking for sys/types.h... yes
checking for sys/stat.h... yes
checking for stdlib.h... yes
checking for string.h... yes
checking for memory.h... yes
checking for strings.h... yes
checking for inttypes.h... yes
checking for stdint.h... yes
checking for unistd.h... yes
checking for string.h... (cached) yes
checking sys/time.h usability... yes
checking sys/time.h presence... yes
checking for sys/time.h... yes
checking for unistd.h... (cached) yes
checking for an ANSI C-conforming const... yes
checking whether time.h and sys/time.h may both be included... yes
configure: checking whether gcc supports static inline...
yes
checking whether setjmp.h is POSIX.1 compatible... yes
checking whether sigsetjmp is declared... yes
checking whether siglongjmp is declared... yes
checking Java support in R... 
/Users/davidparr/.R/Makevars:10: *** missing separator.  Stop.
configure: error: absent
R was configured without Java support. Please run
R CMD javareconf
as root to add Java support to R.

If you do not have root privileges, run
R CMD javareconf -e
to set all Java-related variables and then install rJava.
ERROR: configuration failed for package ‘rJava’
* removing ‘/Library/Frameworks/R.framework/Versions/3.3/Resources/library/rJava’
Warning in install.packages :
  installation of package ‘rJava’ had non-zero exit status

The downloaded source packages are in
    ‘/private/var/folders/lj/4s8lnxmj4_q8h65zk705k6dr0000gn/T/Rtmp7beCd4/downloaded_packages’

现在,当我尝试按照建议运行 R CMD javareconf -e(我不是 root 用户)时,我会在终端中看到以下内容。

trying to compile and link a JNI program 
detected JNI cpp flags    : -I$(JAVA_HOME)/../include -I$(JAVA_HOME)/../include/darwin
detected JNI linker flags : -L$(JAVA_HOME)/lib/server -ljvm
ccache /usr/local/opt/gcc/bin/gcc-6 -Wunused-argument -I/Library/Frameworks/R.framework/Resources/include -DNDEBUG -I/Library/Java/JavaVirtualMachines/jdk1.8.0_131.jdk/Contents/Home/jre/../include -I/Library/Java/JavaVirtualMachines/jdk1.8.0_131.jdk/Contents/Home/jre/../include/darwin -I/usr/local/include -I/usr/local/include/freetype2 -I/opt/X11/include    -fPIC  -Wall -mtune=core2 -g -O2  -c conftest.c -o conftest.o
make: ccache: No such file or directory
make: *** [conftest.o] Error 1
Unable to compile a JNI program 

我在指定的位置肯定有一个文件 gcc-6。为什么CXX=ccache /usr/local/opt/gcc/bin/g++-6 -Wunused-argument 不是CXX=/usr/local/opt/gcc/bin/g++-6

运行sudo R CMD javareconf有无-e比较乐观,虽然我还是不明白-e的意义:

Java interpreter : /usr/bin/java
Java version     : 1.8.0_131
Java home path   : /Library/Java/JavaVirtualMachines/jdk1.8.0_131.jdk/Contents/Home/jre
Java compiler    : /usr/bin/javac
Java headers gen.: /usr/bin/javah
Java archive tool: /usr/bin/jar
Non-system Java on macOS

trying to compile and link a JNI program 
detected JNI cpp flags    : -I$(JAVA_HOME)/../include -I$(JAVA_HOME)/../include/darwin
detected JNI linker flags : -L$(JAVA_HOME)/lib/server -ljvm
/usr/local/opt/gcc/bin/gcc-6 -I/Library/Frameworks/R.framework/Resources/include -DNDEBUG -I/Library/Java/JavaVirtualMachines/jdk1.8.0_131.jdk/Contents/Home/jre/../include -I/Library/Java/JavaVirtualMachines/jdk1.8.0_131.jdk/Contents/Home/jre/../include/darwin -I/usr/local/include -I/usr/local/include/freetype2 -I/opt/X11/include    -fPIC  -Wall -mtune=core2 -g -O2  -c conftest.c -o conftest.o
/usr/local/opt/gcc/bin/gcc-6 -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 conftest.so conftest.o -L/Library/Java/JavaVirtualMachines/jdk1.8.0_131.jdk/Contents/Home/jre/lib/server -ljvm -F/Library/Frameworks/R.framework/.. -framework R -Wl,-framework -Wl,CoreFoundation


JAVA_HOME        : /Library/Java/JavaVirtualMachines/jdk1.8.0_131.jdk/Contents/Home/jre
Java library path: $(JAVA_HOME)/lib/server
JNI cpp flags    : -I$(JAVA_HOME)/../include -I$(JAVA_HOME)/../include/darwin
JNI linker flags : -L$(JAVA_HOME)/lib/server -ljvm
Updating Java configuration in /Library/Frameworks/R.framework/Resources
Done.

【问题讨论】:

  • 为什么这个标签是 gfortran?
  • checking for gcc... /usr/local/opt/llvm/bin/clang -fopenmp -- 你的系统上安装了 OpenMP 吗?如果没有,这可能就是失败的原因。
  • @DaveRGP 我无法访问 macOS 机器,因此我无法就此向您提供建议。 This question 似乎相关;否则我相信你可以通过谷歌搜索找到它。
  • 抱歉,我没有意识到“大部分建议”是三个不同的链接,我只点击了其中一个
  • 这是我使用的~/.R/Makevars 以及使 rJava 工作所需的符号链接。 gist.github.com/hrbrmstr/6f228eead691e72bd0272a25319ea9ee(我通常在安装rJava之前先执行R CMD javareconf)。关于为什么需要 g[++] 工具链与 clang 有一个长篇大论(我没有时间),我想我已经看到人们让它与 clang 一起工作,但我是 g[++ ] 对我来说很好。

标签: r compilation macos-sierra llvm-clang rjava


【解决方案1】:

FWIW,我最近在 Mac 上尝试从 3.4.x 升级到 3.5.1 时遇到了这个问题。

我的3.4.x 安装来自https://cran.r-project.org/,但我使用brew install r 进行升级。

install.packages('rJava') 拒绝使用与此处相同的错误消息:

配置:错误:C 编译器无法创建可执行文件

我来到这里并对更改我的Makevars 中的任何内容持怀疑态度,因为我已经在3.4.x 的机器上启动并运行了大约一年的rJava;事实上我的.R 文件夹是空的。

我终于得出结论,brew 安装是我的问题的根源(或者至少,在我的旧安装和新安装之间发生了一些未解决和隐藏的混淆)并从CRAN 安装网站的.pkg 文件和此问题立即消失。

希望这种体验也能对其他人有所帮助。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2022-01-13
    • 1970-01-01
    • 2023-03-30
    • 2014-01-16
    • 1970-01-01
    相关资源
    最近更新 更多