Install Rstudio-server in CentOS release 6.10 (Final)

本文详细记录了在CentOS 6.10上安装Rstudio-server的过程,包括下载安装包、解决R编译问题、处理字符集错误、配置R环境以及解决依赖问题等步骤,最后成功启动并访问Rstudio-server。

Install Rstudio-server in CentOS release 6.10 (Final)

1. down load rstudio-server-rhel-1.2.5042-x86_64.rpm

2.sudo yum install rstudio-server-rhel-1.2.5042-x86_64.rpm

Resolving Dependencies
--> Running transaction check
---> Package rstudio-server.x86_64 0:1.2.5042-1 will be installed
--> Finished Dependency Resolution

Dependencies Resolved

===============================================
 Package                                         Arch                                    Version                                       Repository                                                             Size
===============================================
Installing:
 rstudio-server                                  x86_64                                  1.2.5042-1                                    /rstudio-server-rhel-1.2.5042-x86_64                                  341 M

Transaction Summary
===============================================
Install       1 Package(s)

Total size: 341 M
Installed size: 341 M
Is this ok [y/N]: y
Downloading Packages:
Running rpm_check_debug
Running Transaction Test
Transaction Test Succeeded
Running Transaction
  Installing : rstudio-server-1.2.5042-1.x86_64                                                                                                                                                                1/1 
groupadd: group 'rstudio-server' already exists
rstudio-server start/running, process 91848
  Verifying  : rstudio-server-1.2.5042-1.x86_64                                                                                                                                                                1/1 

Installed:
  rstudio-server.x86_64 0:1.2.5042-1                                                                                                                                                                               

Complete!

3.   edit /etc/rstudio/rserver.conf

rsession-which-r=/usr/local/bin/R
www-port=8787

4. 然后悲剧地发现R之前编译时没加--enable-R-shlib

$sudo rstudio-server verify-installation
25 Dec 2020 11:35:07 [rserver] ERROR Unable to find libR.so in expected locations within R Home directory /usr/local/lib64/R; LOGGED FROM: bool rstudio::core::r_util::{anonymous}::detectRLocationsUsingR(const string&, rstudio::core::FilePath*, rstudio::core::FilePath*, rstudio::core::config_utils::Variables*, std::string*, const string&) /var/lib/jenkins/workspace/IDE/open-source-pipeline/v1.2-patch/src/cpp/core/r_util/REnvironmentPosix.cpp:552
25 Dec 2020 11:35:08 [rserver] ERROR R shared library (/usr/local/lib64/R/lib/libR.so) not found. If this is a custom build of R, was it built with the --enable-R-shlib option?; LOGGED FROM: bool rstudio::core::r_util::{anonymous}::validateREnvironment(const EnvironmentVars&, const rstudio::core::FilePath&, std::string*) /var/lib/jenkins/workspace/IDE/open-source-pipeline/v1.2-patch/src/cpp/core/r_util/REnvironmentPosix.cpp:368
R shared library (/usr/local/lib64/R/lib/libR.so) not found. If this is a custom build of R, was it built with the --enable-R-shlib option?

5.之前的R装的包太多,不想破坏,于是安装同版本R到别的路径

./configure --enable-R-shlib --prefix=/xxx/xxx/tools/R/R-3.2.2
...
R is now configured for x86_64-pc-linux-gnu

  Source directory:          .
  Installation directory:    /xxx/xxx/tools/R/R-3.2.2

  C compiler:                gcc -std=gnu99  -g -O2
  Fortran 77 compiler:       gfortran  -g -O2

  C++ compiler:              g++  -g -O2
  C++ 11 compiler:           g++  -std=c++0x -g -O2
  Fortran 90/95 compiler:    gfortran -g -O2
  Obj-C compiler:	      

  Interfaces supported:      X11, tcltk
  External libraries:        readline
  Additional capabilities:   NLS
  Options enabled:           shared R library, shared BLAS, R profiling

  Capabilities skipped:      PNG, JPEG, TIFF, cairo, ICU
  Options not enabled:       memory profiling

  Recommended packages:      yes

configure: WARNING: you cannot build info or HTML versions of the R manuals
configure: WARNING: you cannot build PDF versions of the R manuals
configure: WARNING: you cannot build PDF versions of vignettes and help pages

6.以为这样再make&make install就结束了? 太天真了. 意想不到的意外正在后面等着.

$make
...

installing 'sysdata.rda'
make[4]: Leaving directory `/xxx/xxx/install_log/R/R-3.2.2/src/library/tools'
Error in parse(n = -1, file = file, srcfile = NULL, keep.source = FALSE) : 
  invalid multibyte character in parser at line 35075
Error: unable to load R code in package 'tools'
Execution halted

这里的invalid multibyte character in parser at line 35075 来自于之前的一个软件的骚操作使用了GBK字符集, 所以正好由$export LANG="zh_CN.GBK"  触发了错误

后面换'干净'的terminal才正常:

conftest.c: In function 鈥榤ain鈥�:
conftest.c:4: warning: implicit declaration of function 鈥楯NI_CreateJavaVM鈥�
make[2]: *** [conftest.o] Error 1
make[2]: Leaving directory `/tmp/Rjavareconf.tGqgEM'
Unable to compile a JNI program


JAVA_HOME        : /usr/lib/jvm/java-1.7.0-openjdk-1.7.0.221.x86_64/jre
Java library path: 
JNI cpp flags    : 
JNI linker flags : 
Updating Java configuration in /xxx/xxx/install_log/R/R-3.2.2
Done.

验证:

$ls tools/R/R-3.2.2
bin  lib64  share


$ tools/R/R-3.2.2/bin/R
R version 3.2.2 (2015-08-14) -- "Fire Safety"
...
> .libPaths()
[1] "/xxx/xxx/tools/R/R-3.2.2/lib64/R/library"
> q('no')

遗留问题: 因为之前R是装在/usr/local/bin/R, 这导致无法通过$export PATH=$PATH:/xxx/xxx/R/R-3.2.2/bin 使用新安装的

--

ok,到这里为止, R重新装好了.

重新配置rstudio-server后, rstudio-server test-config , rstudio-server verify-installation 都没问题.

然后sudo rstudio-server start 就rstudio-server start/running, process 132020, 和sudo rstudio-server status输出的一样.

--

然后配置防火墙

sudo /etc/init.d/iptables status
Table: nat
Chain PREROUTING (policy ACCEPT)
num  target     prot opt source               destination         
1    DOCKER     all  --  0.0.0.0/0            0.0.0.0/0           ADDRTYPE match dst-type LOCAL 

Chain POSTROUTING (policy ACCEPT)
num  target     prot opt source               destination         
1    MASQUERADE  all  --  172.17.0.0/16        0.0.0.0/0           

Chain OUTPUT (policy ACCEPT)
num  target     prot opt source               destination         
1    DOCKER     all  --  0.0.0.0/0           !127.0.0.0/8         ADDRTYPE match dst-type LOCAL 

Chain DOCKER (2 references)
num  target     prot opt source               destination         

Table: filter
Chain INPUT (policy ACCEPT)
num  target     prot opt source               destination         
1    ACCEPT     all  --  0.0.0.0/0            0.0.0.0/0           state RELATED,ESTABLISHED 
2    ACCEPT     icmp --  0.0.0.0/0            0.0.0.0/0           
3    ACCEPT     all  --  0.0.0.0/0            0.0.0.0/0           
4    ACCEPT     tcp  --  0.0.0.0/0            0.0.0.0/0           state NEW tcp dpt:22 
5    REJECT     all  --  0.0.0.0/0            0.0.0.0/0           reject-with icmp-host-prohibited 

Chain FORWARD (policy ACCEPT)
num  target     prot opt source               destination         
1    DOCKER     all  --  0.0.0.0/0            0.0.0.0/0           
2    ACCEPT     all  --  0.0.0.0/0            0.0.0.0/0           ctstate RELATED,ESTABLISHED 
3    ACCEPT     all  --  0.0.0.0/0            0.0.0.0/0           
4    REJECT     all  --  0.0.0.0/0            0.0.0.0/0           reject-with icmp-host-prohibited 
5    ACCEPT     all  --  0.0.0.0/0            0.0.0.0/0           

Chain OUTPUT (policy ACCEPT)
num  target     prot opt source               destination         

Chain DOCKER (1 references)
num  target     prot opt source               destination   

可以看到分nat和filter 两部分.

$sudo iptables -I INPUT -p tcp --dport 8787 -j ACCEPT
$sudo service iptables restart
iptables: Setting chains to policy ACCEPT: filter          [  OK  ]
iptables: Flushing firewall rules:                         [  OK  ]
iptables: Unloading modules:                               [  OK  ]
iptables: Applying firewall rules:                         [  OK  ]

--
sudo /etc/init.d/iptables status
Table: filter
Chain INPUT (policy ACCEPT)
num  target     prot opt source               destination         
1    ACCEPT     all  --  0.0.0.0/0            0.0.0.0/0           state RELATED,ESTABLISHED 
2    ACCEPT     icmp --  0.0.0.0/0            0.0.0.0/0           
3    ACCEPT     all  --  0.0.0.0/0            0.0.0.0/0           
4    ACCEPT     tcp  --  0.0.0.0/0            0.0.0.0/0           state NEW tcp dpt:22 
5    REJECT     all  --  0.0.0.0/0            0.0.0.0/0           reject-with icmp-host-prohibited 

Chain FORWARD (policy ACCEPT)
num  target     prot opt source               destination         
1    REJECT     all  --  0.0.0.0/0            0.0.0.0/0           reject-with icmp-host-prohibited 

Chain OUTPUT (policy ACCEPT)
num  target     prot opt source               destination  
--
$sudo iptables -I INPUT -p tcp --dport 8787 -j ACCEPT
--
$sudo /etc/init.d/iptables status
Table: filter
Chain INPUT (policy ACCEPT)
num  target     prot opt source               destination         
1    ACCEPT     tcp  --  0.0.0.0/0            0.0.0.0/0           tcp dpt:8787 
2    ACCEPT     all  --  0.0.0.0/0            0.0.0.0/0           state RELATED,ESTABLISHED 
3    ACCEPT     icmp --  0.0.0.0/0            0.0.0.0/0           
4    ACCEPT     all  --  0.0.0.0/0            0.0.0.0/0           
5    ACCEPT     tcp  --  0.0.0.0/0            0.0.0.0/0           state NEW tcp dpt:22 
6    REJECT     all  --  0.0.0.0/0            0.0.0.0/0           reject-with icmp-host-prohibited 

Chain FORWARD (policy ACCEPT)
num  target     prot opt source               destination         
1    REJECT     all  --  0.0.0.0/0            0.0.0.0/0           reject-with icmp-host-prohibited 

Chain OUTPUT (policy ACCEPT)
num  target     prot opt source               destination
--
$sudo /etc/init.d/iptables save
iptables: Saving firewall rules to /etc/sysconfig/iptables:[  OK  ]
--
$sudo service iptables status
Table: filter
Chain INPUT (policy ACCEPT)
num  target     prot opt source               destination         
1    ACCEPT     tcp  --  0.0.0.0/0            0.0.0.0/0           tcp dpt:8787 
2    ACCEPT     all  --  0.0.0.0/0            0.0.0.0/0           state RELATED,ESTABLISHED 
3    ACCEPT     icmp --  0.0.0.0/0            0.0.0.0/0           
4    ACCEPT     all  --  0.0.0.0/0            0.0.0.0/0           
5    ACCEPT     tcp  --  0.0.0.0/0            0.0.0.0/0           state NEW tcp dpt:22 
6    REJECT     all  --  0.0.0.0/0            0.0.0.0/0           reject-with icmp-host-prohibited 

Chain FORWARD (policy ACCEPT)
num  target     prot opt source               destination         
1    REJECT     all  --  0.0.0.0/0            0.0.0.0/0           reject-with icmp-host-prohibited 

Chain OUTPUT (policy ACCEPT)
num  target     prot opt source               destination   

至此, 方可通过浏览器正常访问.

20210203, 补充configure enable关于png, jpg等部分:

#之前没在configure时配置png,jpeg等:
> capabilities()
       jpeg         png        tiff       tcltk         X11        aqua 
      FALSE       FALSE       FALSE        TRUE       FALSE       FALSE 
   http/ftp     sockets      libxml        fifo      cledit       iconv 
       TRUE        TRUE        TRUE        TRUE        TRUE        TRUE 
        NLS     profmem       cairo         ICU long.double     libcurl 
       TRUE       FALSE       FALSE       FALSE        TRUE       FALSE 

#按照编译png必须的包:
yum -y install gcc gcc-c++ autoconf libjpeg libjpeg-devel libpng libpng-devel freetype freetype-devel libxml2 libxml2-devel zlib zlib-devel glibc glibc-devel glib2 glib2-devel bzip2 bzip2-devel ncurses ncurses-devel curl curl-devel e2fsprogs e2fsprogs-devel krb5 krb5-devel libidn libidn-devel openssl openssl-devel openldap openldap-devel nss_ldap openldap-clients openldap-servers gd gd2 gd-devel gd2-devel perl-CPAN pcre-devel

否则会在make时报错:
gcc -fPIC -shared -fopenmp -L/usr/local/lib64  -o libR.so CommandLineArgs.o Rdynload.o Renviron.o RNG.o agrep.o apply.o arithmetic.o array.o attrib.o bind.o builtin.o character.o coerce.o colors.o complex.o connections.o context.o cum.o dcf.o datetime.o debug.o deparse.o devices.o dotcode.o dounzip.o dstruct.o duplicate.o edit.o engine.o envir.o errors.o eval.o format.o gevents.o gram.o gram-ex.o graphics.o grep.o identical.o inlined.o inspect.o internet.o iosupport.o lapack.o list.o localecharset.o logic.o main.o mapply.o match.o memory.o names.o objects.o options.o paste.o platform.o plot.o plot3d.o plotmath.o print.o printarray.o printvector.o printutils.o qsort.o random.o raw.o registration.o relop.o rlocale.o saveload.o scan.o seq.o serialize.o sort.o source.o split.o sprintf.o startup.o subassign.o subscript.o subset.o summary.o sysutils.o times.o unique.o util.o version.o g_alab_her.o g_cntrlify.o g_fontdb.o g_her_glyph.o xxxpr.o   `ls ../unix/*.o ../appl/*.o ../nmath/*.o` ../extra/zlib/libz.a ../extra/bzip2/libbz2.a ../extra/pcre/libpcre.a ../extra/tre/libtre.a  ../extra/xz/liblzma.a   -L../../lib -lRblas -lgfortran -lm   -lreadline  -lrt -ldl -lm  
/usr/bin/ld: CommandLineArgs.o: relocation R_X86_64_32 against `.rodata.str1.1' can not be used when making a shared object; recompile with -fPIC
CommandLineArgs.o: could not read symbols: Bad value
collect2: ld returned 1 exit status
make[3]: *** [libR.so] Error 1

===================================================================================================================================================================================================================
 Package                                                Arch                                         Version                                                   Repository                                     Size
===================================================================================================================================================================================================================
Installing:
 e2fsprogs-devel                                        x86_64                                       1.41.12-24.el6                                            base                                          161 k
 gd                                                     x86_64                                       2.0.35-11.el6                                             base                                          142 k
 gd-devel                                               x86_64                                       2.0.35-11.el6                                             base                                           78 k
 glib2-devel                                            x86_64                                       2.28.8-10.el6                                             base                                          300 k
 libcurl-devel                                          x86_64                                       7.19.7-54.el6_10                                          updates                                       247 k
 libidn-devel                                           x86_64                                       1.18-2.el6                                                base                                          137 k
 libxml2-devel                                          x86_64                                       2.7.6-21.el6_8.1                                          base                                          1.1 M
 openldap-clients                                       x86_64                                       2.4.40-16.el6                                             base                                          166 k
 openldap-devel                                         x86_64                                       2.4.40-16.el6                                             base                                          1.1 M
 openldap-servers                                       x86_64                                       2.4.40-16.el6                                             base                                          2.0 M
 pcre-devel                                             x86_64                                       7.8-7.el6                                                 base                                          320 k
Updating:
 curl                                                   x86_64                                       7.19.7-54.el6_10                                          updates                                       198 k
 freetype                                               x86_64                                       2.3.11-19.el6_10                                          updates                                       361 k
 freetype-devel                                         x86_64                                       2.3.11-19.el6_10                                          updates                                       366 k
 openssl                                                x86_64                                       1.0.1e-58.el6_10                                          updates                                       1.5 M
 openssl-devel                                          x86_64                                       1.0.1e-58.el6_10                                          updates                                       1.2 M
Installing for dependencies:
 cyrus-sasl-devel                                       x86_64                                       2.1.23-15.el6_6.2                                         base                                          303 k
 libXpm                                                 x86_64                                       3.5.10-2.el6                                              base                                           51 k
 libXpm-devel                                           x86_64                                       3.5.10-2.el6                                              base                                           33 k
 libtool-ltdl                                           x86_64                                       2.2.6-15.5.el6                                            base                                           44 k
Updating for dependencies:
 libcurl                                                x86_64                                       7.19.7-54.el6_10                                          updates                                       170 k

Transaction Summary
===================================================================================================================================================================================================================
Install      15 Package(s)
Upgrade       6 Package(s)

Total download size: 9.9 M
Downloading Packages:
(1/21): curl-7.19.7-54.el6_10.x86_64.rpm                                                                                                                                                    | 198 kB     00:00     
(2/21): cyrus-sasl-devel-2.1.23-15.el6_6.2.x86_64.rpm                                                                                                                                       | 303 kB     00:00     
(3/21): e2fsprogs-devel-1.41.12-24.el6.x86_64.rpm                                                                                                                                           | 161 kB     00:00     
(4/21): freetype-2.3.11-19.el6_10.x86_64.rpm                                                                                                                                                | 361 kB     00:00     
(5/21): freetype-devel-2.3.11-19.el6_10.x86_64.rpm                                                                                                                                          | 366 kB     00:00     
(6/21): gd-2.0.35-11.el6.x86_64.rpm                                                                                                                                                         | 142 kB     00:00     
(7/21): gd-devel-2.0.35-11.el6.x86_64.rpm                                                                                                                                                   |  78 kB     00:00     
(8/21): glib2-devel-2.28.8-10.el6.x86_64.rpm                                                                                                                                                | 300 kB     00:00     
(9/21): libXpm-3.5.10-2.el6.x86_64.rpm                                                                                                                                                      |  51 kB     00:00     
(10/21): libXpm-devel-3.5.10-2.el6.x86_64.rpm                                                                                                                                               |  33 kB     00:00     
(11/21): libcurl-7.19.7-54.el6_10.x86_64.rpm                                                                                                                                                | 170 kB     00:00     
(12/21): libcurl-devel-7.19.7-54.el6_10.x86_64.rpm                                                                                                                                          | 247 kB     00:00     
(13/21): libidn-devel-1.18-2.el6.x86_64.rpm                                                                                                                                                 | 137 kB     00:00     
(14/21): libtool-ltdl-2.2.6-15.5.el6.x86_64.rpm                                                                                                                                             |  44 kB     00:00     
(15/21): libxml2-devel-2.7.6-21.el6_8.1.x86_64.rpm                                                                                                                                          | 1.1 MB     00:00     
(16/21): openldap-clients-2.4.40-16.el6.x86_64.rpm                                                                                                                                          | 166 kB     00:00     
(17/21): openldap-devel-2.4.40-16.el6.x86_64.rpm                                                                                                                                            | 1.1 MB     00:00     
(18/21): openldap-servers-2.4.40-16.el6.x86_64.rpm                                                                                                                                          | 2.0 MB     00:00     
(19/21): openssl-1.0.1e-58.el6_10.x86_64.rpm                                                                                                                                                | 1.5 MB     00:00     
(20/21): openssl-devel-1.0.1e-58.el6_10.x86_64.rpm                                                                                                                                          | 1.2 MB     00:00     
(21/21): pcre-devel-7.8-7.el6.x86_64.rpm                                                                                                                                                    | 320 kB     00:00     
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

./configure --enable-R-shlib --with-libpng --with-jpeglib --with-libtiff --with-x --prefix=/home/xxx/tools/R/R-3.2.2
make clean
make
make install

然后就能在rstudio-server里看到:
> capabilities()
       jpeg         png        tiff       tcltk         X11        aqua    http/ftp     sockets      libxml        fifo      cledit 
       TRUE        TRUE        TRUE        TRUE       FALSE       FALSE        TRUE        TRUE        TRUE        TRUE        TRUE 
      iconv         NLS     profmem       cairo         ICU long.double     libcurl 
       TRUE        TRUE       FALSE        TRUE       FALSE        TRUE       FALSE 

20210204 20:11更新, 因为ggplot2, BiocManager等原因, 安装R 3.6.0,  在安装的过程中发现编译R需要升级gcc, 于是又下载gcc编译...

新技能rpm 

$rpm -qa | grep zlib
zlib-1.2.3-29.el6.x86_64
zlib-devel-1.2.3-29.el6.x86_64

checking if zlib version >= 1.2.5... no
checking whether zlib support suffices... configure: error: zlib library and headers are required

$gcc --version
gcc (GCC) 4.4.7 20120313 (Red Hat 4.4.7-23)
Copyright (C) 2010 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

$wget http://www.zlib.net/fossils/zlib-1.2.6.tar.gz

$./configure --prefix=/xxx/yyy/lib/zlib-1.2.6
$make
$make install
$./configure --enable-R-shlib --with-libpng --with-jpeglib --with-libtiff --with-x --prefix=/xxx/yyy/R/R-3.6.0 LDFLAGS="-L/xxx/yyy/lib/zlib-1.2.6/lib" CPPFLAGS="-I/xxx/yyy/lib/zlib-1.2.6/include"

checking if bzip2 version >= 1.0.6... no
这个bzip2有点难下,$wget http://www.bzip.org/1.0.6/bzip2-1.0.6.tar.gz 下不动:

2021-02-03 17:45:59 (169 B/s) - “bzip2-1.0.6.tar.gz.1” saved [16207]

$yum search bzip2
Loaded plugins: fastestmirror, security
Determining fastest mirrors
epel/metalink                                                                                                                      | 4.3 kB     00:00     
 * epel: d2lzkl7pfhq30w.cloudfront.net
base                                                                                                                               | 3.7 kB     00:00     
extras                                                                                                                             | 3.4 kB     00:00     
home_tange                                                                                                                         | 1.3 kB     00:00     
home_tange                                                                                                                                            2/2
updates                                                                                                                            | 3.4 kB     00:00     
=================================================================== N/S Matched: bzip2 ===================================================================
bzip2-devel.i686 : Header files developing apps which will use bzip2
bzip2-devel.x86_64 : Header files developing apps which will use bzip2
bzip2-libs.i686 : Libraries for applications using bzip2
bzip2-libs.x86_64 : Libraries for applications using bzip2
lbzip2.x86_64 : Fast, multi-threaded bzip2 utility
lbzip2-utils.x86_64 : Utilities for working with bzip2 compressed files
pbzip2.x86_64 : Parallel implementation of bzip2
perl-Compress-Raw-Bzip2.x86_64 : Low-Level Interface to bzip2 compression library
perl-IO-Compress-Bzip2.x86_64 : Perl interface to allow reading and writing of bzip2 data
bzip2.x86_64 : A file compression utility
python2-bz2file.noarch : Read and write bzip2-compressed files

  Name and summary matches only, use "search all" for everything.

但后面还是下原码,因为要修改 bzip2-1.0.6 的 Makefile 文件:

$cd bzip2-1.0.6

#修改 bzip2-1.0.6 的 Makefile 文件

CC=gcc -fPIC
AR=ar
RANLIB=ranlib
LDFLAGS=

BIGFILES=-D_FILE_OFFSET_BITS=64



$make -f Makefile-libbz2_so
gcc -fpic -fPIC -Wall -Winline -O2 -g -D_FILE_OFFSET_BITS=64 -c blocksort.c
gcc -fpic -fPIC -Wall -Winline -O2 -g -D_FILE_OFFSET_BITS=64 -c huffman.c
gcc -fpic -fPIC -Wall -Winline -O2 -g -D_FILE_OFFSET_BITS=64 -c crctable.c
gcc -fpic -fPIC -Wall -Winline -O2 -g -D_FILE_OFFSET_BITS=64 -c randtable.c
gcc -fpic -fPIC -Wall -Winline -O2 -g -D_FILE_OFFSET_BITS=64 -c compress.c
gcc -fpic -fPIC -Wall -Winline -O2 -g -D_FILE_OFFSET_BITS=64 -c decompress.c
gcc -fpic -fPIC -Wall -Winline -O2 -g -D_FILE_OFFSET_BITS=64 -c bzlib.c
gcc -shared -Wl,-soname -Wl,libbz2.so.1.0 -o libbz2.so.1.0.6 blocksort.o huffman.o crctable.o randtable.o compress.o decompress.o bzlib.o
gcc -fpic -fPIC -Wall -Winline -O2 -g -D_FILE_OFFSET_BITS=64 -o bzip2-shared bzip2.c libbz2.so.1.0.6
rm -f libbz2.so.1.0
ln -s libbz2.so.1.0.6 libbz2.so.1.0

$make clean
rm -f *.o libbz2.a bzip2 bzip2recover \
	sample1.rb2 sample2.rb2 sample3.rb2 \
	sample1.tst sample2.tst sample3.tst

$make

If compilation produces errors, or a large number of warnings,
please read README.COMPILATION.PROBLEMS -- you might be able to
adjust the flags in this Makefile to improve matters.

Also in README.COMPILATION.PROBLEMS are some hints that may help
if your build produces an executable which is unable to correctly
handle so-called 'large files' -- files of size 2GB or more.

gcc -Wall -Winline -O2 -g -D_FILE_OFFSET_BITS=64 -c blocksort.c
gcc -Wall -Winline -O2 -g -D_FILE_OFFSET_BITS=64 -c huffman.c
gcc -Wall -Winline -O2 -g -D_FILE_OFFSET_BITS=64 -c crctable.c
gcc -Wall -Winline -O2 -g -D_FILE_OFFSET_BITS=64 -c randtable.c
gcc -Wall -Winline -O2 -g -D_FILE_OFFSET_BITS=64 -c compress.c
gcc -Wall -Winline -O2 -g -D_FILE_OFFSET_BITS=64 -c decompress.c
gcc -Wall -Winline -O2 -g -D_FILE_OFFSET_BITS=64 -c bzlib.c
rm -f libbz2.a
ar cq libbz2.a blocksort.o huffman.o crctable.o randtable.o compress.o decompress.o bzlib.o
ranlib libbz2.a
gcc -Wall -Winline -O2 -g -D_FILE_OFFSET_BITS=64 -c bzip2.c
gcc -Wall -Winline -O2 -g -D_FILE_OFFSET_BITS=64  -o bzip2 bzip2.o -L. -lbz2
gcc -Wall -Winline -O2 -g -D_FILE_OFFSET_BITS=64 -c bzip2recover.c
gcc -Wall -Winline -O2 -g -D_FILE_OFFSET_BITS=64  -o bzip2recover bzip2recover.o

Doing 6 tests (3 compress, 3 uncompress) ...
If there's a problem, things might stop at this point.
 
./bzip2 -1  < sample1.ref > sample1.rb2
./bzip2 -2  < sample2.ref > sample2.rb2
./bzip2 -3  < sample3.ref > sample3.rb2
./bzip2 -d  < sample1.bz2 > sample1.tst
./bzip2 -d  < sample2.bz2 > sample2.tst
./bzip2 -ds < sample3.bz2 > sample3.tst
cmp sample1.bz2 sample1.rb2 
cmp sample2.bz2 sample2.rb2
cmp sample3.bz2 sample3.rb2
cmp sample1.tst sample1.ref
cmp sample2.tst sample2.ref
cmp sample3.tst sample3.ref

If you got this far and the 'cmp's didn't complain, it looks
like you're in business.  

To install in /usr/local/bin, /usr/local/lib, /usr/local/man and 
/usr/local/include, type

   make install

To install somewhere else, eg, /xxx/yyy/{bin,lib,man,include}, type 

   make install PREFIX=/xxx/yyy

If you are (justifiably) paranoid and want to see what 'make install'
is going to do, you can first do

   make -n install                      or
   make -n install PREFIX=/xxx/yyy      respectively.

The -n instructs make to show the commands it would execute, but
not actually execute them.

Instructions for use are in the preformatted manual page, in the file
bzip2.txt.  For more detailed documentation, read the full manual.  
It is available in Postscript form (manual.ps), PDF form (manual.pdf),
and HTML form (manual.html).

You can also do "bzip2 --help" to see some helpful information. 
"bzip2 -L" displays the software license.


$make -n install PREFIX=/xxx/yyy/lib/bzip2-1.0.6
$make install PREFIX=/xxx/yyy/lib/bzip2-1.0.6


...
checking for BZ2_bzlibVersion in -lbz2... yes
checking bzlib.h usability... yes
checking bzlib.h presence... yes
checking for bzlib.h... yes
checking if bzip2 version >= 1.0.6... yes

checking for lzma_version_number in -llzma... no
configure: error: "liblzma library and headers are required"
 

$wget https://nchc.dl.sourceforge.net/project/lzmautils/xz-5.2.3.tar.gz

$./configure --prefix=/xxx/yyy/lib/xz-5.2.3

make
make install 


$./configure --enable-R-shlib --with-libpng --with-jpeglib --with-libtiff --with-x --prefix=/xxx/yyy/R/R-3.6.0 LDFLAGS="-L/xxx/yyy/lib/zlib-1.2.6/lib -L/xxx/yyy/lib/bzip2-1.0.6/lib  -L/xxx/yyy/lib/xz-5.2.3/lib " CPPFLAGS="-I/xxx/yyy/lib/zlib-1.2.6/include -I/xxx/yyy//lib/bzip2-1.0.6/include -I/xxx/yyy/lib/xz-5.2.3/include "
...

checking for lzma_version_number in -llzma... yes
checking lzma.h usability... yes
checking lzma.h presence... yes
checking for lzma.h... yes
checking if lzma version >= 5.0.3... yes

checking for pcre_fullinfo in -lpcre... yes
checking pcre.h usability... yes
checking pcre.h presence... yes
checking for pcre.h... yes
checking pcre/pcre.h usability... no
checking pcre/pcre.h presence... no
checking for pcre/pcre.h... no
checking if PCRE version >= 8.20, < 10.0 and has UTF-8 support... no
checking whether PCRE support suffices... configure: error: pcre >= 8.20 library and headers are required

$wget https://ftp.pcre.org/pub/pcre/pcre-8.40.tar.gz --no-check-certificate
$./configure --prefix=/xxx/yyy/lib/pcre-8.40

C preprocessor .................. : gcc -E
    C compiler ...................... : gcc
    C++ preprocessor ................ : g++ -E
    C++ compiler .................... : g++
    Linker .......................... : /usr/bin/ld -m elf_x86_64
    C preprocessor flags ............ : 
    C compiler flags ................ : -g -O2 -fvisibility=hidden
    C++ compiler flags .............. : -O2 -fvisibility=hidden -fvisibility-inlines-hidden
    Linker flags .................... : 
    Extra libraries ................. : 

    Build 8 bit pcre library ........ : yes
    Build 16 bit pcre library ....... : no
    Build 32 bit pcre library ....... : no
    Build C++ library ............... : yes
    Enable JIT compiling support .... : no
    Enable UTF-8/16/32 support ...... : no
    Unicode properties .............. : no
    Newline char/sequence ........... : lf
    \R matches only ANYCRLF ......... : no
    EBCDIC coding ................... : no
    EBCDIC code for NL .............. : n/a
    Rebuild char tables ............. : no
    Use stack recursion ............. : yes
    POSIX mem threshold ............. : 10
    Internal link size .............. : 2
    Nested parentheses limit ........ : 250
    Match limit ..................... : 10000000
    Match limit recursion ........... : MATCH_LIMIT
    Build shared libs ............... : yes
    Build static libs ............... : yes
    Use JIT in pcregrep ............. : no
    Buffer size for pcregrep ........ : 20480
    Link pcregrep with libz ......... : no
    Link pcregrep with libbz2 ....... : no
    Link pcretest with libedit ...... : no
    Link pcretest with libreadline .. : no
    Valgrind support ................ : no
    Code coverage ................... : no


checking if PCRE version >= 8.20, < 10.0 and has UTF-8 support... no
checking whether PCRE support suffices... configure: error: pcre >= 8.20 library and headers are required

--->UTF-8 support... no

$./configure --prefix=/xxx/yyy/lib/pcre-8.40 -enable-utf8
...
Enable UTF-8/16/32 support ...... : yes
...

...
checking for pcre_fullinfo in -lpcre... yes
checking pcre.h usability... yes
checking pcre.h presence... yes
checking for pcre.h... yes
checking pcre/pcre.h usability... no
checking pcre/pcre.h presence... no
checking for pcre/pcre.h... no
checking if PCRE version >= 8.20, < 10.0 and has UTF-8 support... yes
checking if PCRE version >= 8.32... yes
checking whether PCRE support suffices... yes
checking for pcre2-config... no


checking for curl-config... /usr/local/bin/conda/miniconda/bin/curl-config
checking libcurl version ... 7.60.0
checking curl/curl.h usability... yes
checking curl/curl.h presence... yes
checking for curl/curl.h... yes
checking if libcurl is version 7 and >= 7.22.0... no
configure: error: libcurl >= 7.22.0 library and headers are required with support for https

$wget https://curl.haxx.se/download/curl-7.64.1.tar.gz --no-check-certificate
#照旧configure,make,make install.
#但后面R的configure写错了路径, 鄙视一下分心.


...
checking for curl-config... /usr/local/bin/conda/miniconda/bin/curl-config
checking libcurl version ... 7.60.0
checking curl/curl.h usability... yes
checking curl/curl.h presence... yes
checking for curl/curl.h... yes
checking if libcurl is version 7 and >= 7.22.0... yes
checking if libcurl supports https... yes
checking if jpeglib version >= 6b... yes
checking for jpeg_destroy_compress in -ljpeg... yes
checking if libpng version >= 1.2.7... yes
checking for png_create_write_struct in -lpng... yes
checking whether leap seconds are treated according to POSIX... yes
checking for inline... inline

R的configure这关算是过了,但make报错:

...
gcc -std=gnu99 -I../../src/extra  -I. -I../../src/include -I../../src/include ...

/usr/bin/ld: warning: libpcre.so.1, needed by ../../lib/libR.so, not found (try using -rpath or -rpath-link)
/usr/bin/ld: warning: liblzma.so.5, needed by ../../lib/libR.so, not found (try using -rpath or -rpath-link)
../../lib/libR.so: undefined reference to `lzma_code@XZ_5.0'
../../lib/libR.so: undefined reference to `lzma_raw_encoder@XZ_5.0'
../../lib/libR.so: undefined reference to `lzma_stream_decoder@XZ_5.0'
../../lib/libR.so: undefined reference to `pcre_free'
../../lib/libR.so: undefined reference to `lzma_lzma_preset@XZ_5.0'
../../lib/libR.so: undefined reference to `lzma_raw_decoder@XZ_5.0'
../../lib/libR.so: undefined reference to `libiconv'
../../lib/libR.so: undefined reference to `pcre_version'
../../lib/libR.so: undefined reference to `pcre_exec'
../../lib/libR.so: undefined reference to `pcre_config'
../../lib/libR.so: undefined reference to `libiconv_close'
../../lib/libR.so: undefined reference to `_libiconv_version'
../../lib/libR.so: undefined reference to `pcre_fullinfo'
../../lib/libR.so: undefined reference to `pcre_maketables'
../../lib/libR.so: undefined reference to `libiconv_open'
../../lib/libR.so: undefined reference to `pcre_compile'
../../lib/libR.so: undefined reference to `pcre_assign_jit_stack'
../../lib/libR.so: undefined reference to `lzma_end@XZ_5.0'
../../lib/libR.so: undefined reference to `lzma_alone_decoder@XZ_5.0'
../../lib/libR.so: undefined reference to `lzma_version_string@XZ_5.0'
../../lib/libR.so: undefined reference to `lzma_crc64@XZ_5.0'
../../lib/libR.so: undefined reference to `pcre_jit_stack_alloc'
../../lib/libR.so: undefined reference to `pcre_study'
../../lib/libR.so: undefined reference to `pcre_free_study'
../../lib/libR.so: undefined reference to `lzma_stream_encoder@XZ_5.0'
collect2: ld returned 1 exit status

j据说是因为gcc版本太低,于是又倒回去折腾gcc

$wget ftp://ftp.gnu.org/gnu/gcc/gcc-4.8.5/gcc-4.8.5.tar.gz

#编译安装 GCC 需要依赖 mpc,mpfr,gmp,isl 包。前四个包是 GNU 软件,$ ./contrib/download_prerequisites下载;
#最后一个 isl 不是 GNU 项目,需要我们手动去下载。
$ wget http://isl.gforge.inria.fr/isl-0.14.tar.gz
$ tar zvxf isl-0.14.tar.gz
$ ln -s lsl isl-0.14

#为了避免在编译过程中,受原来系统自定义的一堆环境影响,建议先 unset 这些环境设置:
$ unset LIBRARY_PATH CPATH C_INCLUDE_PATH PKG_CONFIG_PATH CPLUS_INCLUDE_PATH INCLUDE

$ ABSOLUTE_PATH/configure -enable-checking=release -enable-languages=c,c++ -disable-multilib --prefix=/xxx/yyy/gcc-4.8.5
$ make 
$ make install

configure必须用绝对路径,否则make install时报错:
/bin/sh: line 3: cd: ./fixincludes: No such file or directory
make[1]: *** [install-fixincludes] Error 1

Wed Feb 03 21:08:13 321 gcc-4.8.5/gcc-build-4.8.5

$make -j 48
Wed Feb 03 21:16:59 322 gcc-4.8.5/gcc-build-4.8.5

48core真快,  耗时8:46

 

gcc-4.8.5/bin/gcc -dumpversion
4.8.5
 

$./configure CC=/xxx/tools/gcc-4.8.5/bin/gcc CXX=/home/yangming/tools/gcc-4.8.5/bin/c++  --enable-R-shlib --with-libpng --with-jpeglib --with-libtiff --with-x --prefix=/xxx/tools/R/R-3.6.0 LDFLAGS="-L.../lib"  CPPFLAGS="-I.../include"

还是报同样的错误.

gcc-4.8.5/bin/gcc -std=gnu99 -Wl,--export-dynamic -fopenmp  -L"...



/usr/bin/ld: warning: libpcre.so.1, needed by ../../lib/libR.so, not found (try using -rpath or -rpath-link)
/usr/bin/ld: warning: liblzma.so.5, needed by ../../lib/libR.so, not found (try using -rpath or -rpath-link)
../../lib/libR.so: undefined reference to `lzma_code@XZ_5.0'
../../lib/libR.so: undefined reference to `lzma_raw_encoder@XZ_5.0'
../../lib/libR.so: undefined reference to `lzma_stream_decoder@XZ_5.0'
../../lib/libR.so: undefined reference to `pcre_free'
../../lib/libR.so: undefined reference to `lzma_lzma_preset@XZ_5.0'
../../lib/libR.so: undefined reference to `lzma_raw_decoder@XZ_5.0'
../../lib/libR.so: undefined reference to `libiconv'
../../lib/libR.so: undefined reference to `pcre_version'
../../lib/libR.so: undefined reference to `pcre_exec'
../../lib/libR.so: undefined reference to `pcre_config'
../../lib/libR.so: undefined reference to `libiconv_close'
../../lib/libR.so: undefined reference to `_libiconv_version'
../../lib/libR.so: undefined reference to `pcre_fullinfo'
../../lib/libR.so: undefined reference to `pcre_maketables'
../../lib/libR.so: undefined reference to `libiconv_open'
../../lib/libR.so: undefined reference to `pcre_compile'
../../lib/libR.so: undefined reference to `pcre_assign_jit_stack'
../../lib/libR.so: undefined reference to `lzma_end@XZ_5.0'
../../lib/libR.so: undefined reference to `lzma_alone_decoder@XZ_5.0'
../../lib/libR.so: undefined reference to `lzma_version_string@XZ_5.0'
../../lib/libR.so: undefined reference to `lzma_crc64@XZ_5.0'
../../lib/libR.so: undefined reference to `pcre_jit_stack_alloc'
../../lib/libR.so: undefined reference to `pcre_study'
../../lib/libR.so: undefined reference to `pcre_free_study'
../../lib/libR.so: undefined reference to `lzma_stream_encoder@XZ_5.0'
collect2: error: ld returned 1 exit status
make[3]: *** [R.bin] Error 1

此时因修改$vim Makeconf

LDFLAGS = -L/...
 -Wl,-rpath=/xxx/yyy/lib/pcre-8.40/lib
 -Wl,-rpath=/xxx/yyy/lib/xz-5.2.3/lib

上面错误消失,变成了

gcc-4.8.5/bin/gcc -std=gnu99 -Wl,--export-dynamic -fopenmp  -L"../../lib" -L ... -Wl,-rpath=/xxx/yyy/lib/pcre-8.40/lib -Wl,-rpath=/xxx/yyy/lib/xz-5.2.3/lib -o R.bin Rmain.o  -lR -lRblas
../../lib/libR.so: undefined reference to `libiconv'
../../lib/libR.so: undefined reference to `libiconv_close'
../../lib/libR.so: undefined reference to `_libiconv_version'
../../lib/libR.so: undefined reference to `libiconv_open'
collect2: error: ld returned 1 exit status
make[3]: *** [R.bin] Error 1

$locate libiconv.so.2出来的几个版本都不对,
libiconv.so.2.6.0

libiconv.so.2.5.1
下原码:

$wget https://ftp.gnu.org/pub/gnu/libiconv/libiconv-1.14.tar.gz

...
$./configure --prefix=/xxx/yyy/lib/libiconv-1.14
make & make install

...
R-3.6.0 
$vim Makeconf

...

算是编译过了.

下面错误JAVA没装SDK

*** installing help indices
** building package indices
** testing if installed package can be loaded
* DONE (mgcv)

...

configuring Java ...
Java interpreter : /usr/bin/java
Java version     : 1.7.0_221
Java home path   : /usr/lib/jvm/java-1.7.0-openjdk-1.7.0.221.x86_64/jre
Java compiler    : not present
Java headers gen.: 
Java archive tool: 

trying to compile and link a JNI program 
detected JNI cpp flags    : 
detected JNI linker flags : -L$(JAVA_HOME)/lib/amd64/server -ljvm
make[2]: Entering directory `/tmp/Rjavareconf.buCQwx'

...
conftest.c:1:17: fatal error: jni.h: No such file or directory
 #include <jni.h>
                 ^
compilation terminated.
make[2]: *** [conftest.o] Error 1
make[2]: Leaving directory `/tmp/Rjavareconf.buCQwx'
Unable to compile a JNI program


JAVA_HOME        : /usr/lib/jvm/java-1.7.0-openjdk-1.7.0.221.x86_64/jre
Java library path: 
JNI cpp flags    : 
JNI linker flags : 

Done.

make[1]: Leaving directory xxxx

但在拷贝NEWS.pdf时又出现问题:

$make install
...
/usr/bin/install: cannot stat `NEWS.pdf': No such file or directory
/usr/bin/install: cannot stat `NEWS.pdf': No such file or directory
make[1]: *** [install-sources2] Error 1
make[1]: Leaving directory xxx
make: *** [install] Error 1

这个问题搞了我好久,但至少R是装好了:

> capabilities()
       jpeg         png        tiff       tcltk         X11        aqua 
       TRUE        TRUE       FALSE        TRUE       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       FALSE        TRUE        TRUE 
> q('no')

最后简单粗暴解决:

R-3.6.0 
$cp doc/NEWS doc/NEWS.pdf



然后$make install成功.

但这还不算完, 装ggplot2时报错, 需要改/usr/lib64/libstdc++.so.6的指向

$ll /usr/lib64/libstdc++.so.6
lrwxrwxrwx. 1 root root 19 Jun  2  2019 /usr/lib64/libstdc++.so.6 -> libstdc++.so.6.0.13

$strings /usr/lib64/libstdc++.so.6 | grep GLIBCXX
GLIBCXX_3.4
GLIBCXX_3.4.1
GLIBCXX_3.4.2
GLIBCXX_3.4.3
GLIBCXX_3.4.4
GLIBCXX_3.4.5
GLIBCXX_3.4.6
GLIBCXX_3.4.7
GLIBCXX_3.4.8
GLIBCXX_3.4.9
GLIBCXX_3.4.10
GLIBCXX_3.4.11
GLIBCXX_3.4.12
GLIBCXX_3.4.13
GLIBCXX_FORCE_NEW
GLIBCXX_DEBUG_MESSAGE_LENGTH


$strings /xxx/yyy/gcc-4.8.5/lib64/libstdc++.so.6 | grep GLIBCXX
GLIBCXX_3.4
GLIBCXX_3.4.1
GLIBCXX_3.4.2
GLIBCXX_3.4.3
GLIBCXX_3.4.4
GLIBCXX_3.4.5
GLIBCXX_3.4.6
GLIBCXX_3.4.7
GLIBCXX_3.4.8
GLIBCXX_3.4.9
GLIBCXX_3.4.10
GLIBCXX_3.4.11
GLIBCXX_3.4.12
GLIBCXX_3.4.13
GLIBCXX_3.4.14
GLIBCXX_3.4.15
GLIBCXX_3.4.16
GLIBCXX_3.4.17
GLIBCXX_3.4.18
GLIBCXX_3.4.19
GLIBCXX_FORCE_NEW
GLIBCXX_DEBUG_MESSAGE_LENGTH


$sudo ln -sf /xxx/tools/gcc-4.8.5/lib64/libstdc++.so.6.0.19 /usr/lib64/libstdc++.so.6


$strings /usr/lib64/libstdc++.so.6 | grep GLIBC
GLIBCXX_3.4
GLIBCXX_3.4.1
GLIBCXX_3.4.2
GLIBCXX_3.4.3
GLIBCXX_3.4.4
GLIBCXX_3.4.5
GLIBCXX_3.4.6
GLIBCXX_3.4.7
GLIBCXX_3.4.8
GLIBCXX_3.4.9
GLIBCXX_3.4.10
GLIBCXX_3.4.11
GLIBCXX_3.4.12
GLIBCXX_3.4.13
GLIBCXX_3.4.14
GLIBCXX_3.4.15
GLIBCXX_3.4.16
GLIBCXX_3.4.17
GLIBCXX_3.4.18
GLIBCXX_3.4.19
GLIBC_2.3
GLIBC_2.2.5
GLIBC_2.3.2
GLIBCXX_FORCE_NEW
GLIBCXX_DEBUG_MESSAGE_LENGTH

至此,算是经过九九八十一难完成.

下面加入环境变量

$export R_HOME=/xxx/yyy/tools/R/R-3.6.0
$export R_LIBS=/xxx/yyy/tools/R/R-3.6.0/lib64/R/library/
$export LD_LIBRARY_PATH=$R_HOME/lib:$LD_LIBRARY_PATH
$export PATH=$R_HOME/bin:$PATH

 

参考:

https://blog.csdn.net/weixin_36118025/article/details/112664193

https://www.jianshu.com/p/1a1a52c2caa2?utm_campaign=maleskine&utm_content=note&utm_medium=seo_notes&utm_source=recommendation

https://blog.51cto.com/191226139/2066137

https://www.jianshu.com/p/5bfe154f1aa4?from=timeline

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值