UbuntuにRパッケージのgmpをインストールする方法を備忘録として残しておきます。

CライブラリGMP(GNU Multiple Precision Arithmetic)を使用した「制限なしの算術」、複数の高精度算術(大きな整数と有理数、素数検定、行列計算)を行うことのできるパッケージです。

RStudioのコンソールでgmpパッケージをインストールしようとすると、次のように表示されてインストールできません。これは、Ubuntu上にgmpライブラリがないことが原因です。


> install.packages("gmp")

* installing *source* package ‘gmp’ ...
**  パッケージ ‘gmp’ の解凍および MD5 サムの検証に成功しました 
creating cache ./config.cache
checking for __gmpz_ui_sub in -lgmp... no
configure: error: GNU MP not found, or not 4.1.4 or up, see http://gmplib.org
ERROR: configuration failed for package ‘gmp’
* removing '/home/[home-user]/R/x86_64-pc-linux-gnu-library/3.4/gmp'
Warning in install.packages :
  installation of package ‘gmp’ had non-zero exit status

そのため、ターミナルで次のコマンドを実行することによりUbuntu上にgmpライブラリをインストールします。


$ sudo apt-get install libgmp3-dev

Ubuntu上にgmpライブラリをインストールした後、RStudioのコンソールでgmpパッケージをインストールすれば成功します。


> install.packages("gmp")

* installing *source* package ‘gmp’ ...
**  パッケージ ‘gmp’ の解凍および MD5 サムの検証に成功しました 
creating cache ./config.cache
checking for __gmpz_ui_sub in -lgmp... yes
updating cache ./config.cache
creating ./config.status
creating src/Makevars
** libs
g++  -I/usr/share/R/include -DNDEBUG -I/usr/local/include/       -fpic  -g -O2 -fstack-protector-strong -Wformat -Werror=format-security -Wdate-time -D_FORTIFY_SOURCE=2 -g  -c apply.cc -o apply.o
g++  -I/usr/share/R/include -DNDEBUG -I/usr/local/include/       -fpic  -g -O2 -fstack-protector-strong -Wformat -Werror=format-security -Wdate-time -D_FORTIFY_SOURCE=2 -g  -c biginteger.cc -o biginteger.o
g++  -I/usr/share/R/include -DNDEBUG -I/usr/local/include/       -fpic  -g -O2 -fstack-protector-strong -Wformat -Werror=format-security -Wdate-time -D_FORTIFY_SOURCE=2 -g  -c bigintegerR.cc -o bigintegerR.o
g++  -I/usr/share/R/include -DNDEBUG -I/usr/local/include/       -fpic  -g -O2 -fstack-protector-strong -Wformat -Werror=format-security -Wdate-time -D_FORTIFY_SOURCE=2 -g  -c bigmod.cc -o bigmod.o
g++  -I/usr/share/R/include -DNDEBUG -I/usr/local/include/       -fpic  -g -O2 -fstack-protector-strong -Wformat -Werror=format-security -Wdate-time -D_FORTIFY_SOURCE=2 -g  -c bigrational.cc -o bigrational.o
g++  -I/usr/share/R/include -DNDEBUG -I/usr/local/include/       -fpic  -g -O2 -fstack-protector-strong -Wformat -Werror=format-security -Wdate-time -D_FORTIFY_SOURCE=2 -g  -c bigrationalR.cc -o bigrationalR.o
g++  -I/usr/share/R/include -DNDEBUG -I/usr/local/include/       -fpic  -g -O2 -fstack-protector-strong -Wformat -Werror=format-security -Wdate-time -D_FORTIFY_SOURCE=2 -g  -c bigvec.cc -o bigvec.o
g++  -I/usr/share/R/include -DNDEBUG -I/usr/local/include/       -fpic  -g -O2 -fstack-protector-strong -Wformat -Werror=format-security -Wdate-time -D_FORTIFY_SOURCE=2 -g  -c bigvec_q.cc -o bigvec_q.o
g++  -I/usr/share/R/include -DNDEBUG -I/usr/local/include/       -fpic  -g -O2 -fstack-protector-strong -Wformat -Werror=format-security -Wdate-time -D_FORTIFY_SOURCE=2 -g  -c extract_matrix.cc -o extract_matrix.o
g++  -I/usr/share/R/include -DNDEBUG -I/usr/local/include/       -fpic  -g -O2 -fstack-protector-strong -Wformat -Werror=format-security -Wdate-time -D_FORTIFY_SOURCE=2 -g  -c factor.cc -o factor.o
g++  -I/usr/share/R/include -DNDEBUG -I/usr/local/include/       -fpic  -g -O2 -fstack-protector-strong -Wformat -Werror=format-security -Wdate-time -D_FORTIFY_SOURCE=2 -g  -c factorize.cc -o factorize.o
g++  -I/usr/share/R/include -DNDEBUG -I/usr/local/include/       -fpic  -g -O2 -fstack-protector-strong -Wformat -Werror=format-security -Wdate-time -D_FORTIFY_SOURCE=2 -g  -c init.cc -o init.o
g++  -I/usr/share/R/include -DNDEBUG -I/usr/local/include/       -fpic  -g -O2 -fstack-protector-strong -Wformat -Werror=format-security -Wdate-time -D_FORTIFY_SOURCE=2 -g  -c matrix.cc -o matrix.o
g++  -I/usr/share/R/include -DNDEBUG -I/usr/local/include/       -fpic  -g -O2 -fstack-protector-strong -Wformat -Werror=format-security -Wdate-time -D_FORTIFY_SOURCE=2 -g  -c matrixq.cc -o matrixq.o
g++  -I/usr/share/R/include -DNDEBUG -I/usr/local/include/       -fpic  -g -O2 -fstack-protector-strong -Wformat -Werror=format-security -Wdate-time -D_FORTIFY_SOURCE=2 -g  -c solve.cc -o solve.o
g++ -shared -L/usr/lib/R/lib -Wl,-Bsymbolic-functions -Wl,-z,relro -o gmp.so apply.o biginteger.o bigintegerR.o bigmod.o bigrational.o bigrationalR.o bigvec.o bigvec_q.o extract_matrix.o factor.o factorize.o init.o matrix.o matrixq.o solve.o -L/usr/local/lib/ -lgmp -L/usr/lib/R/lib -lR
installing to /home/[home-user]/R/x86_64-pc-linux-gnu-library/3.4/gmp/libs
** R
** data
** preparing package for lazy loading
Creating a generic function for ‘which.max’ from package ‘base’ in package ‘gmp’
Creating a generic function for ‘which.min’ from package ‘base’ in package ‘gmp’
** help
*** installing help indices
** building package indices

Attaching package: ‘gmp’

The following objects are masked from ‘package:base’:

    %*%, apply, crossprod, matrix, tcrossprod

	** testing if installed package can be loaded
	* DONE (gmp)
Ubuntu,R gmpパッケージをインストールする方法