R Makevars文件未正确覆盖g ++

时间:2018-02-14 20:59:00

标签: c++ r rstudio

我试图安装R套餐' lubridate'因为lubridate需要比Centos 6上的标准编译器更新版本的g ++,我下载并编译了版本gcc 4.9(从我读过的内容来看,lubridate需要> v4.8)

然后我添加了一行:

CXX=/opt/gcc_4.9.1/rtf/bin/g++
CC=/opt/gcc_4.9.1/rtf/bin/gcc -std=gnu99

到〜/ .R / Makevars文件,尝试强制它使用更新的编译器,但是当我尝试安装lubridate时出现此错误:

> install.packages("lubridate")
trying URL 'https://cran.rstudio.com/src/contrib/lubridate_1.7.2.tar.gz'
Content type 'application/x-gzip' length 450988 bytes (440 KB)
==================================================
downloaded 440 KB

* installing *source* package ‘lubridate’ ...
** package ‘lubridate’ successfully unpacked and MD5 sums checked
** libs
g++ -std=c++0x -I/opt/R/R-3.3.3/include -DNDEBUG -I. -I./cctz/include/ -I./cctz/src/ -I/usr/local/include -I"/opt/R/R-3.3.3/library/Rcpp/include"   -fpic  -g -O2 -c RcppExports.cpp -o RcppExports.o
/opt/gcc_4.9.1/rtf/bin/gcc -std=gnu99 -I/opt/R/R-3.3.3/include -DNDEBUG -I. -I./cctz/include/ -I./cctz/src/ -I/usr/local/include -I"/opt/R/R-3.3.3/library/Rcpp/include"  -O3 -Wall -pipe -pedantic -std=gnu99 -fopenmp -fpic  -O3 -Wall -pipe -pedantic -std=gnu99 -fopenmp -c datetime.c -o datetime.o
/opt/gcc_4.9.1/rtf/bin/gcc -std=gnu99 -I/opt/R/R-3.3.3/include -DNDEBUG -I. -I./cctz/include/ -I./cctz/src/ -I/usr/local/include -I"/opt/R/R-3.3.3/library/Rcpp/include"  -O3 -Wall -pipe -pedantic -std=gnu99 -fopenmp -fpic  -O3 -Wall -pipe -pedantic -std=gnu99 -fopenmp -c period.c -o period.o
/opt/gcc_4.9.1/rtf/bin/gcc -std=gnu99 -I/opt/R/R-3.3.3/include -DNDEBUG -I. -I./cctz/include/ -I./cctz/src/ -I/usr/local/include -I"/opt/R/R-3.3.3/library/Rcpp/include"  -O3 -Wall -pipe -pedantic -std=gnu99 -fopenmp -fpic  -O3 -Wall -pipe -pedantic -std=gnu99 -fopenmp -c tparse.c -o tparse.o
tparse.c: In function ‘C_parse_dt’:
tparse.c:338:26: warning: ‘oMIN’ may be used uninitialized in this function [-Wmaybe-uninitialized]
         INTEGER(oMIN)[i] = M;
                          ^
tparse.c:337:27: warning: ‘oHOUR’ may be used uninitialized in this function [-Wmaybe-uninitialized]
         INTEGER(oHOUR)[i] = H;
                           ^
tparse.c:336:26: warning: ‘oDAY’ may be used uninitialized in this function [-Wmaybe-uninitialized]
         INTEGER(oDAY)[i] = d;
                          ^
tparse.c:335:28: warning: ‘oMONTH’ may be used uninitialized in this function [-Wmaybe-uninitialized]
         INTEGER(oMONTH)[i] = m - 1;
                            ^
tparse.c:334:27: warning: ‘oYEAR’ may be used uninitialized in this function [-Wmaybe-uninitialized]
         INTEGER(oYEAR)[i] = y - 1900;
                           ^
g++ -std=c++0x -I/opt/R/R-3.3.3/include -DNDEBUG -I. -I./cctz/include/ -I./cctz/src/ -I/usr/local/include -I"/opt/R/R-3.3.3/library/Rcpp/include"   -fpic  -g -O2 -c update.cpp -o update.o
In file included from ./cctz/include/civil_time.h:18,
                 from update.cpp:3:
./cctz/include/civil_time_detail.h:37: error: expected nested-name-specifier before ‘year_t’
./cctz/include/civil_time_detail.h:37: error: ‘year_t’ has not been declared
./cctz/include/civil_time_detail.h:37: error: expected ‘;’ before ‘=’ token
./cctz/include/civil_time_detail.h:37: error: expected unqualified-id before ‘=’ token
./cctz/include/civil_time_detail.h:41: error: expected nested-name-specifier before ‘diff_t’
./cctz/include/civil_time_detail.h:41: error: ‘diff_t’ has not been declared
./cctz/include/civil_time_detail.h:41: error: expected ‘;’ before ‘=’ token
./cctz/include/civil_time_detail.h:41: error: expected unqualified-id before ‘=’ token
./cctz/include/civil_time_detail.h:46: error: expected nested-name-specifier before ‘month_t’
./cctz/include/civil_time_detail.h:46: error: ‘month_t’ has not been declared
./cctz/include/civil_time_detail.h:46: error: expected ‘;’ before ‘=’ token
./cctz/include/civil_time_detail.h:46: error: expected unqualified-id before ‘=’ token
./cctz/include/civil_time_detail.h:47: error: expected nested-name-specifier before ‘day_t’
./cctz/include/civil_time_detail.h:47: error: ‘day_t’ has not been declared
./cctz/include/civil_time_detail.h:47: error: expected ‘;’ before ‘=’ token
./cctz/include/civil_time_detail.h:47: error: expected unqualified-id before ‘=’ token
./cctz/include/civil_time_detail.h:48: error: expected nested-name-specifier before ‘hour_t’
./cctz/include/civil_time_detail.h:48: error: ‘hour_t’ has not been declared
./cctz/include/civil_time_detail.h:48: error: expected ‘;’ before ‘=’ token
./cctz/include/civil_time_detail.h:48: error: expected unqualified-id before ‘=’ token
./cctz/include/civil_time_detail.h:49: error: expected nested-name-specifier before ‘minute_t’
./cctz/include/civil_time_detail.h:49: error: ‘minute_t’ has not been declared
./cctz/include/civil_time_detail.h:49: error: expected ‘;’ before ‘=’ token
./cctz/include/civil_time_detail.h:49: error: expected unqualified-id before ‘=’ token
./cctz/include/civil_time_detail.h:50: error: expected nested-name-specifier before ‘second_t’
./cctz/include/civil_time_detail.h:50: error: ‘second_t’ has not been declared
./cctz/include/civil_time_detail.h:50: error: expected ‘;’ before ‘=’ token
./cctz/include/civil_time_detail.h:50: error: expected unqualified-id before ‘=��� token
./cctz/include/civil_time_detail.h:54: error: expected ‘)’ before ‘year’
./cctz/include/civil_time_detail.h:78: error: ‘cctz::detail::impl::is_leap_year’ declared as an ‘inline’ variable
./cctz/include/civil_time_detail.h:78: error: ‘year_t’ was not declared in this scope
./cctz/include/civil_time_detail.h:78: error: expected ‘,’ or ‘;’ before ‘noexcept’
./cctz/include/civil_time_detail.h:81: error: ‘cctz::detail::impl::year_index’ declared as an ‘inline’ variable
./cctz/include/civil_time_detail.h:81: error: ‘year_t’ was not declared in this scope
./cctz/include/civil_time_detail.h:81: error: ‘month_t’ was not declared in this scope
./cctz/include/civil_time_detail.h:81: error: initializer expression list treated as compound expression
./cctz/include/civil_time_detail.h:81: error: expected ‘,’ or ‘;’ before ‘noexcept’
./cctz/include/civil_time_detail.h:84: error: ‘cctz::detail::impl::days_per_century’ declared as an ‘inline’ variable
./cctz/include/civil_time_detail.h:84: error: ‘year_t’ was not declared in this scope
./cctz/include/civil_time_detail.h:84: error: ‘month_t’ was not declared in this scope
./cctz/include/civil_time_detail.h:84: error: initializer expression list treated as compound expression
./cctz/include/civil_time_detail.h:84: error: expected ‘,’ or ‘;’ before ‘noexcept’
./cctz/include/civil_time_detail.h:88: error: ‘cctz::detail::impl::days_per_4years’ declared as an ‘inline’ variable
./cctz/include/civil_time_detail.h:88: error: ‘year_t’ was not declared in this scope
./cctz/include/civil_time_detail.h:88: error: ‘month_t’ was not declared in this scope
./cctz/include/civil_time_detail.h:88: error: initializer expression list treated as compound expression
./cctz/include/civil_time_detail.h:88: error: expected ‘,’ or ‘;’ before ‘noexcept’
./cctz/include/civil_time_detail.h:92: error: ‘cctz::detail::impl::days_per_year’ declared as an ‘inline’ variable
./cctz/include/civil_time_detail.h:92: error: ‘year_t’ was not declared in this scope
./cctz/include/civil_time_detail.h:92: error: ‘month_t’ was not declared in this scope
./cctz/include/civil_time_detail.h:92: error: initializer expression list treated as compound expression
./cctz/include/civil_time_detail.h:92: error: expected ‘,’ or ‘;’ before ‘noexcept’
./cctz/include/civil_time_detail.h:95: error: ‘cctz::detail::impl::days_per_month’ declared as an ‘inline’ variable
./cctz/include/civil_time_detail.h:95: error: ‘year_t’ was not declared in this scope
./cctz/include/civil_time_detail.h:95: error: ‘month_t’ was not declared in this scope
./cctz/include/civil_time_detail.h:95: error: initializer expression list treated as compound expression
./cctz/include/civil_time_detail.h:95: error: expected ‘,’ or ‘;’ before ‘noexcept’
update.cpp:452: error: expected ‘}’ at end of input
update.cpp:452: error: expected ‘}’ at end of input
update.cpp:452: error: expected ‘}’ at end of input
make: *** [update.o] Error 1
ERROR: compilation failed for package ‘lubridate’
* removing ‘/opt/R/R-3.3.3/library/lubridate’
Warning in install.packages :
  installation of package ‘lubridate’ had non-zero exit status

The downloaded source packages are in
    ‘/tmp/RtmpRwMbsZ/downloaded_packages’
Updating HTML index of packages in '.Library'
Making 'packages.html' ... done

有趣的是,它似乎正在尝试正确使用正确的gcc:

/opt/gcc_4.9.1/rtf/bin/gcc -std=gnu99 -I/opt/R/R-3.3.3/include -DNDEBUG -I. -I./cctz/include/ -I./cctz/src/ -I/usr/local/include -I"/opt/R/R-3.3.3/library/Rcpp/include"  -O3 -Wall -pipe -pedantic -std=gnu99 -fopenmp -fpic  -O3 -Wall -pipe -pedantic -std=gnu99 -fopenmp -c datetime.c -o datetime.o

但不是正确的g ++(没有列出我在〜/ .R / Makevars文件中定义的完整路径):

g++ -std=c++0x -I/opt/R/R-3.3.3/include -DNDEBUG -I. -I./cctz/include/ -I./cctz/src/ -I/usr/local/include -I"/opt/R/R-3.3.3/library/Rcpp/include"   -fpic  -g -O2 -c RcppExports.cpp -o RcppExports.o

如果我将〜/ .R / Makevars文件中的行更改为:

CXX=g++
CC=gcc

然后看起来两个可执行文件都成为正常的系统:

g++ -std=c++0x -I/opt/R/R-3.3.3/include -DNDEBUG -I. -I./cctz/include/ -I./cctz/src/ -I/usr/local/include -I"/opt/R/R-3.3.3/library/Rcpp/include"   -fpic  -g -O2 -c RcppExports.cpp -o RcppExports.o
gcc -I/opt/R/R-3.3.3/include -DNDEBUG -I. -I./cctz/include/ -I./cctz/src/ -I/usr/local/include -I"/opt/R/R-3.3.3/library/Rcpp/include"  -O3 -Wall -pipe -pedantic -std=gnu99 -fopenmp -fpic  -O3 -Wall -pipe -pedantic -std=gnu99 -fopenmp -c datetime.c -o datetime.o

是否有另一个文件优先于〜/ .R / Makevars文件中定义的g ++位置?真正的问题是如何让R在这里使用/opt/gcc_4.9.1/rtf/bin/g++?

1 个答案:

答案 0 :(得分:0)

看来我需要在〜/ .R / Makevars文件中设置CXX1X=/opt/gcc_4.9.1/rtf/bin/g++,之后rubridate包使用了预期的g ++,并成功编译。不幸的是,由于R无法加载库,这还没有完全解决我的问题:

** testing if installed package can be loaded
Error in dyn.load(file, DLLpath = DLLpath, ...) :
  unable to load shared object '/opt/R/R-3.3.3/library/lubridate/libs/lubridate.so':
  /usr/lib64/libstdc++.so.6: version `GLIBCXX_3.4.18' not found (required by /opt/R/R-3.3.3/library/lubridate/libs/lubridate.so)
Error: loading failed
Execution halted
ERROR: loading failed
* removing ‘/opt/R/R-3.3.3/library/lubridate’

看起来R正在使用/usr/lib64/libstdc++.so.6,而不是(可能是?)使用/opt/gcc_4.9.1/rtf/lib64/libstdc++.so.6。但它确实解决了我在这里问的问题。如果我能弄清楚如何加载它,我会在这里回复,以防其他人试图做同样的事情。感谢RolandASc指出我正确的方向。