等一杯咖啡 2017-03-09
SUSE Linux Enterprise Server 11 SP3源码编译安装R-3.2.2过程详解。suse上安装R,过程艰难,文章里的源码包版本都是自己安装时候所用的版本,不一定必须是该版本。
整体依赖关系:
cairo依赖于X11 , pango依赖于cairo
安装顺序X11 -> cairo -> pango
1.安装编译器
先看看R网站的一些说明:
B.6 Using FORTRAN:
.................
To compile R, you need a FORTRAN compiler.
The default is to search for f95, fort, xlf95, ifort,ifc, efc, pgf95 lf95, gfortran, ftn, g95, f90,
xlf90, pghpf, pgf90, epcf90, g77, f77, xlf, frt,pgf77, cf77, fort77, fl32, af77 (in that order)56,
and use whichever is found first; if none is found, Rcannot be compiled. However,
if CC is gcc, the matching FORTRAN compiler (g77 forgcc 3 and gfortran for gcc 4) is used if available
suse默认是没有gfortran编辑器,所以需要先安装它
xz -d gcc-trunk.tar.xz
tar -xvf gcc-trunk.tar -C /opt
vi /etc/profile
export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/opt/gcc-trunk/lib64:/opt/gcc-trunk/lib
exportLIBRARY_PATH=$LIBRARY_PATH:/opt/gcc-trunk/lib:/opt/gcc-trunk/lib64
export PATH=$PATH:/opt/gcc-trunk/bin
source /etc/profile
which gfortran
/opt/gcc-trunk/bin/gfortran
还需要安装gcc-c++
zypper in gcc-c++
2.安装Xorg-X11
安装cairo需要xlib支持,所有需要X11支持,编译R需要X11的libX11和libXt
2.1安装libX11-1.6.5
依赖关系(a,b-> c c依赖于a,b):
(libpthread-stubs-0.3,xcb-proto-1.12,libXau-1.0.4) -> libxcb-1.12
(util-macros-1.19.1,kbproto-1.0.4,xproto-7.0.23,inputproto-2.3.2,xextproto-7.0.3)-> libX11-1.6.5 <- (libxcb-1.12)
1)安装util-macros-1.19.1
./configure --prefix=/usr/local
make install
2)安装kbproto-1.0.4
./configure --prefix=/usr/local
make install
3)安装xproto-7.0.23
./configure --prefix=/usr/local
make
make install
4)安装inputproto-2.3.2
./configure --prefix=/usr/local
make
make install
5)安装xextproto-7.0.3
./configure --prefix=/usr/local
make install
6)安装libpthread-stubs-0.3
./configure --prefix=/usr/local
make
make install
7)安装xcb-proto-1.12
./configure --prefix=/usr/local
make
make install
8)安装libXau-1.0.4
./configure --prefix=/usr/local
make
make install
9)安装libxcb-1.12
./configure --prefix=/usr/local
make
make install
10)安装libX11-1.6.5
2.2安装libXt-1.1.5
依赖关系(a,b-> c c依赖于a,b)
(xtrans-1.3.5,libice_1.0.8,libsm_1.2.1) -> libXt-1.1.5
1)安装xtrans-1.3.5
./configure --prefix=/usr/local
make
make install
2)安装libICE-1.0.8
./configure --prefix=/usr/local
make
make install
3)安装libsm_1.2.1
./configure --prefix=/usr/local
make
make install
4)安装libXt-1.1.5
./configure --prefix=/usr/local
make
make install
3.安装cairo-1.14.8
R网站的说明:
A.2 Useful libraries and programs:
..............
The ‘modern’ version of the X11(), jpeg(), png() andtiff() graphics devices uses the cairo and (optionally) Pango libraries.
Cairo version 1.2.0 or later is required.
Pango needs to be at least version 1.10, and 1.12 isthe earliest version we have tested.
(For Fedora users we believe the pango-devel RPM andits dependencies suffice.)
R checks for pkg-config, and uses that to check firstthat the ‘pangocairo’ package is installed (and if not, ‘cairo’)
and if additional flags are needed for the‘cairo-xlib’ package,
then if suitable code can be compiled.
These tests will fail if pkg-config is notinstalled48, and are likely to fail if cairo was built statically (unusual).
Most systems with Gtk+ 2.8 or later installed willhave suitable libraries
..............
需要cairo-xlib的支持(需要安装X11)
依赖关系:(a,b-> c c依赖于a,b)
(libXext-1.0.1,pixman-0.34.0)-> cairo-1.14.8
1)安装libXext-1.0.1
./configure --prefix=/usr/local
make
make install
2)安装pixman-0.34.0
./configure --prefix=/usr/local
make
make install
2)安装cairo-1.14.8
./configure --prefix=/usr/local --disable-static --enable-xlib=yes--enable-ft=yes --enable-xlib-xcb=yes -enable-tee
make
make install
configure的结果:
Thefollowing font backends:
User: yes (always builtin)
FreeType: yes
Fontconfig: yes
Win32: no (requires a Win32 platform)
Quartz: no (requires CoreGraphics framework)
The following functions:
PNGfunctions: yes
GLXfunctions: no (not required by anybackend)
WGLfunctions: no (not required by anybackend)
EGLfunctions: no (not required by anybackend)
X11-xcbfunctions: yes
XCB-shmfunctions: yes
The following features and utilities:
cairo-trace: yes
cairo-script-interpreter: yes
And the following internal features:
pthread: yes
gtk-doc: no
gcovsupport: no
symbol-lookup: no (requires bfd)
testsurfaces: no (disabled, use --enable-test-surfaces to enable)
pstesting: no (requires libspectre)
pdftesting: no (requires poppler-glib>= 0.17.4)
svgtesting: no (requires librsvg-2.0 >=2.35.0)
4.安装pango
依赖关系:(a,b -> c c依赖于a,b):
(libffi-3.2,pcre-8.40 ) -> glib-2.48.2
(libpng-1.6.28,readline-6.3) ->freetype-2.5.4 -> fontconfig-2.12.0 -> harfbuzz-1.4.0 <-(icu4c-50_1,glib-2.48.2)
harfbuzz-1.4.0 -> pango-1.40.2
1)编译libpng-1.6.28
rpm-ivh --nodeps zlib-devel-1.2.7-7.1.1.x86_64.rpm --freetype需要
./configure --prefix=/usr/local
make
make install
2)编译readline-6.3
./configure --prefix=/usr/local
make
make install
3)安装freetype-2.5.4
./configure --prefix=/usr/local
make
make install
4)编译fontconfig-2.12.0
rpm-ivh --nodeps libxml2-devel-2.7.6-0.23.1.x86_64.rpm --fontconfig需要
./configure --sysconfdir=/etc --prefix=/usr/local--mandir=/usr/share/man --enable-libxml2
make
make install
5)编译icu4c-50_1
./configure --prefix=/usr/local
make
make install
6)编译libffi-3.2
./configure --prefix=/usr/local
make
make install
7)编译pcre-8.40
./configure --enable-utf8 --enable-unicode-properties--prefix=/usr/local
make
make install
8)编译glib-2.48.2(最好是这个版本)
./configure --prefix=/usr/local
make
make install
9)编译harfbuzz-1.4.0
./configure --prefix=/usr/local
make
make install
configure结果:
Unicode callbacks (you want at least one):
Glib: true
ICU: true
UCDN: false
10)编译pango-1.40.2
./configure --prefix=/usr/local
make
make install
5.安装R-3.2.2
依赖关系(a->b b依赖于a):
gmp-5.1.3 -> isl-0.13
mpfr-3.1.5 -> mpc-1.0.2
jpeg9b
tiff-4.0.7
1)安装ncurses-devel(readline的依赖)
zypper in ncurses-devel
2)安装gmp-5.1.3
./configure --prefix=/usr/local
make
make install
2)安装isl-0.13
./configure --prefix=/usr/local
make
make install
3)安装mpfr-3.1.5
./configure --prefix=/usr/local
make
make install
4)安装mpc-1.0.2
./configure --prefix=/usr/local
make
make install
5)安装jpeg-9b
./configure --prefix=/usr/local
make
make install
6)安装tiff-4.0.7
./configure --prefix=/usr/local
make
make install
7)安装R-3.2.2
./configure --enable-R-shlib --with-readline=yes --with-jpeglib=yes--with-libpng=yes --with-x=yes --with-libtiff=yes --with-cairo=yes--with-ICU=yes --prefix=/opt/R
make (如果没有java环境还需要安装java)
make install
8)vi /etc/profile
export PATH=$PATH:/opt/gcc-trunk/bin:/opt/R/bin
source /etc/profiel
可以开始使用R了
R
> capabilities()
jpeg png tiff tcltk X11 aqua
TRUE TRUE TRUE FALSE FALSE FALSE
http/ftp sockets libxml fifo cledit iconv
TRUE TRUE TRUE TRUE TRUE TRUE
NLS profmem cairo ICU long.double libcurl
TRUE FALSE TRUE TRUE TRUE FALSE
option
R安装ggplot2
https://cran.r-project.org/web/packages/available_packages_by_name.html
依赖于:
digest, gtable (≥ 0.1.1), plyr (≥ 1.7.1),reshape2, scales (≥ 0.4.1), tibble, lazyeval
Rcpp -> plyr
stringi,magrittr -> stringr -> reshape2
lazyeval,assertthat -> tibble
RColorBrewer,dichromat,(colorspace -> munsell),labeling -> scales
1)R CMD INSTALL digest_0.6.12.tar.gz
2)R CMD INSTALL gtable_0.2.0.tar.gz
3)R CMD INSTALL Rcpp_0.12.9.tar.gz
4)R CMD INSTALL plyr_1.8.4.tar.gz
5)R CMD INSTALL stringi_1.1.2.tar.gz
6)R CMD INSTALL magrittr_1.5.tar.gz
7)R CMD INSTALL stringr_1.2.0.tar.gz
8)R CMD INSTALL reshape2_1.4.2.tar.gz
9)R CMD INSTALL lazyeval_0.2.0.tar.gz
10)R CMD INSTALL assertthat_0.1.tar.gz
11)R CMD INSTALL tibble_1.2.tar.gz
12)R CMD INSTALL RColorBrewer_1.1-2.tar.gz
13)R CMD INSTALL dichromat_2.0-0.tar.gz
14)R CMD INSTALL colorspace_1.3-2.tar.gz
15)R CMD INSTALL munsell_0.4.3.tar.gz
16)R CMD INSTALL labeling_0.3.tar.gz
17)R CMD INSTALL scales_0.4.1.tar.gz
18)R CMD INSTALL ggplot2_2.2.1.tar.gz
R
>library()
Packages in library ‘/opt/R/lib64/R/library’:
KernSmooth Functions for Kernel SmoothingSupporting Wand
& Jones (1995)
MASS Support Functions andDatasets for Venables and
Ripley's MASS
Matrix Sparse and Dense MatrixClasses and Methods
RColorBrewer ColorBrewer Palettes
Rcpp Seamless R and C++ Integration
assertthat Easy pre and post assertions.
base The R Base Package
boot Bootstrap Functions(Originally by Angelo Canty
for S)
class Functions for Classification
cluster "Finding Groups inData": Cluster Analysis
Extended Rousseeuw etal.
codetools Code Analysis Tools for R
colorspace Color Space Manipulation
compiler The R Compiler Package
datasets The R Datasets Package
dichromat Color Schemes for Dichromats
digest Create Compact Hash Digestsof R Objects
foreign Read Data Stored by Minitab,S, SAS, SPSS,
Stata, Systat, Weka,dBase, ...
ggplot2 Create Elegant DataVisualisations Using the
Grammar of Graphics
FAQ
在安装R的过程中遇到的一些问题
1. R依赖
R官方网站说明:
The ‘modern’ version of the X11(), jpeg(),png() and tiff() graphics devices uses the cairo and (optionally) Pangolibraries.
Cairo version 1.2.0 or later is required.
Pango needs to be at least version 1.10,and 1.12 is the earliest version we have tested.
(For Fedora users we believe thepango-devel RPM and its dependencies suffice.)
R checks for pkg-config, and uses that tocheck first that the ‘pangocairo’ package is installed (and if not, ‘cairo’)
and if additional flags are needed for the‘cairo-xlib’ package,
then if suitable code can be compiled.
These tests will fail if pkg-config is notinstalled48,
and are likely to fail if cairo was builtstatically (unusual).
Most systems with Gtk+ 2.8 or laterinstalled will have suitable libraries
需要pango和cairo,并且cairo需要cairo-xlib支持
2. --with-x=yes (default) andX11 headers/libs are not available
编译R时报错:
checking X11/Intrinsic.h usability... no
checking X11/Intrinsic.h presence... no
checking for X11/Intrinsic.h... no
configure: error: --with-x=yes (default)and X11 headers/libs are not available
解决办法: install libXt
3. dchdc.o: could not readsymbols: Bad value
make R时报错:
/usr/lib64/gcc/x86_64-suse-linux/4.3/../../../../x86_64-suse-linux/bin/ld:
../appl/dchdc.o: relocation R_X86_64_32against `.rodata' can not be used when making a shared object; recompile with-fPIC
../appl/dchdc.o: could not read symbols:Bad value
collect2: ld returned 1 exit status
解决办法: configura时去掉--enable-R-shlib
4. error: cairo-xlib.h: No suchfile or directory
编译R时报错:
configure:31534: checking for X
configure:31720: result: disabled
configure:32391: result: using X11 ... no
configure:32501: checking whetherpkg-config knows about cairo and pango
configure:32513: result: yes
configure:32547: checking whether cairoincluding pango is >= 1.2 and works
configure:32570: gcc -std=gnu99 -o conftest-g -O2 -fpic -I/usr/local/include -I/usr/include/libxml2-I/usr/local/include/pango-1.0 -I/usr/local/include/cairo-I/usr/local/include/harfbuzz -I/usr/local/include/freetype2-I/usr/local/include -I/usr/local/include/glib-2.0-I/usr/local/lib/glib-2.0/include -I/usr/local/include/pixman-1 -I/usr/local/include/libpng16 -L/usr/local/lib64 conftest.c -lrt -ldl-lm -L/usr/local/lib -lpangocairo-1.0-lpango-1.0 -lgobject-2.0 -lglib-2.0 -lpng16 -lz -lcairo >&5
conftest.c:233:24: error: cairo-xlib.h: Nosuch file or directory
configure:32570: $? = 1
解决办法:这是安装了cairo,但是编译cairo时没有加--enable-xlib=yes参数
5. /libreadline.so: undefined reference to….
configure R时候readline报错,查看config.log:
configure:20905: checking forrl_callback_read_char in -lreadline
configure:20930: gcc -o conftest -g -O2-I/usr/local/include -L/usr/local/lib64 conftest.c -lreadline >&5
/usr/local/lib/libreadline.so: undefinedreference to `tputs'
/usr/local/lib/libreadline.so: undefinedreference to `tgoto'
/usr/local/lib/libreadline.so: undefinedreference to `tgetflag'
/usr/local/lib/libreadline.so: undefinedreference to `UP'
/usr/local/lib/libreadline.so: undefinedreference to `tgetent'
/usr/local/lib/libreadline.so: undefinedreference to `tgetnum'
/usr/local/lib/libreadline.so: undefinedreference to `PC'
/usr/local/lib/libreadline.so: undefinedreference to `tgetstr'
/usr/local/lib/libreadline.so: undefinedreference to `BC'
collect2: ld returned 1 exit status
configure:20930: $? = 1
解决办法: zypper in ncurses-devel
6. error: cannot compile a simple Fortranprogram
configure R 时候报错:
checking for Fortran 77 libraries ofgfortran...
checking how to get verbose linking outputfrom gcc -std=gnu99... -v
checking for C libraries of gcc-std=gnu99... -L/usr/local/lib64-L/usr/lib64/gcc/x86_64-suse-linux/4.3 -L/usr/lib64/gcc/x86_64-suse-linux/4.3/../../../../lib64-L/lib/../lib64 -L/usr/lib/../lib64-L/usr/lib64/gcc/x86_64-suse-linux/4.3/../../../../x86_64-suse-linux/lib-L/usr/lib64/gcc/x86_64-suse-linux/4.3/../../.. -lgcc_s
checking for dummy main to link withFortran 77 libraries... none
checking for Fortran 77 name-manglingscheme... configure: error: in `/soft/R-3.2.2':
configure: error: cannot compile a simpleFortran program
config.log中搜索"cannotcompile a simple Fortran program":
configure:23745: checking for Fortran 77name-mangling scheme
configure:23758: gfortran -c conftest.f >&5
/opt/gcc-trunk/bin/../libexec/gcc/x86_64-pc-linux-gnu/7.0.0/f951:error while loading shared libraries: libisl.so.13: cannot open sh
ared object file: No such file or directory
configure:23758: $? = 1
configure: failed program was:
| subroutine foobar()
| return
| end
| subroutine foo_bar()
| return
| end
configure:23891: error: in `/soft/R-3.2.2':
configure:23893: error: cannot compile asimple Fortran program
解决办法:安装isl
7. undefined reference to….
make R时报错
gcc -std=gnu99 -Wl,--export-dynamic-fopenmp -L../../lib -L/usr/local/lib64-o R.bin Rmain.o -lR -lRblas
/opt/gcc-trunk/lib64/libgfortran.so.4:undefined reference to `__cpu_model@GCC_4.8.0'
collect2: ld returned 1 exit status
make[3]: *** [R.bin] Error 1
解决办法:
/etc/profile里添加:
exportLIBRARY_PATH=$LIBRARY_PATH:/opt/gcc-trunk/lib:/opt/gcc-trunk/lib64
source /etc/profile