gpt4 book ai didi

r - 无法从源代码安装 rJava 为 "C Compiler works ... no"

转载 作者:行者123 更新时间:2023-12-04 12:28:58 24 4
gpt4 key购买 nike

根据 much of the advice在 SE 上关于让 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?

使用和不使用 -e 运行 sudo R CMD javareconf 更乐观,虽然我仍然不明白 -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.

最佳答案

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

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

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

configure: error: C compiler cannot create executables

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

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

希望这些经验对其他人也有帮助。

关于r - 无法从源代码安装 rJava 为 "C Compiler works ... no",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43632512/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com