gpt4 book ai didi

c++ - R Makevars 文件没有正确覆盖 g++

转载 作者:太空宇宙 更新时间:2023-11-04 12:51:38 25 4
gpt4 key购买 nike

我正在尝试在 Centos 6 上安装 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++?

最佳答案

看来我需要在 ~/.R/Makevars 文件中设置 CXX1X=/opt/gcc_4.9.1/rtf/bin/g++,之后 lubridate 包使用了预期的 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++。所以.6。但它确实解决了我在这里问的问题。如果我能弄清楚如何加载它,我会发回这里,以防其他人试图做同样的事情。感谢 RolandASc 为我指明了正确的方向。

关于c++ - R Makevars 文件没有正确覆盖 g++,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48796089/

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