Ubuntu 18.04下安装R包rjsoncons遇cpp11库writable歧义错误
解决Ubuntu 18.04下安装R包rjsoncons的编译错误
解决步骤
- 降级cpp11包到0.4.5版本:
# 查看当前cpp11版本 packageVersion("cpp11") # 卸载当前版本 remove.packages("cpp11") # 安装兼容版本 install.packages("cpp11", version = "0.4.5") - 重新安装rjsoncons:
install.packages("rjsoncons", repos = "https://CRAN.R-project.org")
错误原因
编译错误核心是cpp11库中writable命名空间存在歧义:新版本cpp11在declarations.hpp中添加了namespace writable = ::cpp11::writable;的别名,同时r_vector.hpp中本身定义了cpp11::writable命名空间,导致编译器无法确定代码中引用的writable指向哪个。而rjsoncons 1.2.0的代码未适配cpp11的这个命名空间变化,因此降级cpp11到未引入该别名的0.4.5版本即可解决问题。
原始错误日志
**Installing package into ‘/home/ignatius/R/x86_64-pc-linux-gnu-library/4.3’ **# (as ‘lib’ is unspecified) **trying URL 'https://CRAN.R-project.org/src/contrib/rjsoncons_1.2.0.tar.gz' Content type 'application/x-gzip' length 578073 bytes (564 KB) **# ==================================================** **downloaded 564 KB * installing *source* package ‘rjsoncons’ ... ** package ‘rjsoncons’ successfully unpacked and MD5 sums checked ** using staged installation ** libs using C++ compiler: ‘g++ (Ubuntu 7.5.0-3ubuntu1~18.04) 7.5.0’ g++ -std=gnu++17 -I"/usr/share/R/include" -DNDEBUG -I../inst/include/ -I'/home/ignatius/R/x86_64-pc-linux-gnu-library/4.3/cpp11/include' -fpic -g -O2 -fdebug-prefix-map=/build/r-base-WnOgSi/r-base-4.3.3=. -fstack-protector-strong -Wformat -Werror=format-security -Wdate-time -D_FORTIFY_SOURCE=2 -c cpp11.cpp -o cpp11.o g++ -std=gnu++17 -I"/usr/share/R/include" -DNDEBUG -I../inst/include/ -I'/home/ignatius/R/x86_64-pc-linux-gnu-library/4.3/cpp11/include' -fpic -g -O2 -fdebug-prefix-map=/build/r-base-WnOgSi/r-base-4.3.3=. -fstack-protector-strong -Wformat -Werror=format-security -Wdate-time -D_FORTIFY_SOURCE=2 -c rjsoncons.cpp -o rjsoncons.o In file included from rjsoncons.cpp:8:0: j_as.h: In function ‘cpp11::sexp as_r(Json)’: j_as.h:165:22: error: reference to ‘writable’ is ambiguous result = writable::list(j.size()); // default: NULL elements ^~~~~~~~ In file included from rjsoncons.cpp:1:0: /home/ignatius/R/x86_64-pc-linux-gnu-library/4.3/cpp11/include/cpp11/declarations.hpp:14:39: note: candidates are: namespace writable = cpp11::cpp11::writable; namespace writable = ::cpp11::writable; ^ In file included from /home/ignatius/R/x86_64-pc-linux-gnu-library/4.3/cpp11/include/cpp11/list.hpp:10:0, from /home/ignatius/R/x86_64-pc-linux-gnu-library/4.3/cpp11/include/cpp11/data_frame.hpp:12, from /home/ignatius/R/x86_64-pc-linux-gnu-library/4.3/cpp11/include/cpp11.hpp:7, from /home/ignatius/R/x86_64-pc-linux-gnu-library/4.3/cpp11/include/cpp11/declarations.hpp:13, from rjsoncons.cpp:1: /home/ignatius/R/x86_64-pc-linux-gnu-library/4.3/cpp11/include/cpp11/r_vector.hpp:44:11: note: namespace cpp11::writable { } namespace writable { ^~~~~~~~ In file included from rjsoncons.cpp:8:0: j_as.h:169:22: error: parse error in template argument list result = j_as_r_vector<writable::logicals, bool>(j); ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ j_as.h:173:22: error: parse error in template argument list result = j_as_r_vector<writable::integers, int32_t>(j); ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ j_as.h:177:22: error: parse error in template argument list result = j_as_r_vector<writable::doubles, double>(j); ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ j_as.h:181:22: error: parse error in template argument list result = j_as_r_vector<writable::strings, std::string>(j); ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ j_as.h:186:13: error: reference to ‘writable’ is ambiguous writable::list value(j.size()); ^~~~~~~~ In file included from rjsoncons.cpp:1:0: /home/ignatius/R/x86_64-pc-linux-gnu-library/4.3/cpp11/include/cpp11/declarations.hpp:14:39: note: candidates are: namespace writable = cpp11::cpp11::writable; namespace writable = ::cpp11::writable; ^ In file included from /home/ignatius/R/x86_64-pc-linux-gnu-library/4.3/cpp11/include/cpp11/list.hpp:10:0, from /home/ignatius/R/x86_64-pc-linux-gnu-library/4.3/cpp11/include/cpp11/data_frame.hpp:12, from /home/ignatius/R/x86_64-pc-linux-gnu-library/4.3/cpp11/include/cpp11.hpp:7, from /home/ignatius/R/x86_64-pc-linux-gnu-library/4.3/cpp11/include/cpp11/declarations.hpp:13, from rjsoncons.cpp:1: /home/ignatius/R/x86_64-pc-linux-gnu-library/4.3/cpp11/include/cpp11/r_vector.hpp:44:11: note: namespace cpp11::writable { } namespace writable { ^~~~~~~~ In file included from rjsoncons.cpp:8:0: j_as.h:188:67: error: ‘value’ was not declared in this scope j.array_range().cbegin(), j.array_range().cend(), value.begin(), ^~~~~ j_as.h:188:67: note: suggested alternative: ‘valloc’ j.array_range().cbegin(), j.array_range().cend(), value.begin(), ^~~~~ valloc j_as.h:196:9: error: reference to ‘writable’ is ambiguous writable::list value(j.size()); ^~~~~~~~ In file included from rjsoncons.cpp:1:0: /home/ignatius/R/x86_64-pc-linux-gnu-library/4.3/cpp11/include/cpp11/declarations.hpp:14:39: note: candidates are: namespace writable = cpp11::cpp11::writable; namespace writable = ::cpp11::writable; ^ In file included from /home/ignatius/R/x86_64-pc-linux-gnu-library/4.3/cpp11/include/cpp11/list.hpp:10:0, from /home/ignatius/R/x86_64-pc-linux-gnu-library/4.3/cpp11/include/cpp11/data_frame.hpp:12, from /home/ignatius/R/x86_64-pc-linux-gnu-library/4.3/cpp11/include/cpp11.hpp:7, from /home/ignatius/R/x86_64-pc-linux-gnu-library/4.3/cpp11/include/cpp11/declarations.hpp:13, from rjsoncons.cpp:1: /home/ignatius/R/x86_64-pc-linux-gnu-library/4.3/cpp11/include/cpp11/r_vector.hpp:44:11: note: namespace cpp11::writable { } namespace writable { ^~~~~~~~ In file included from rjsoncons.cpp:8:0: j_as.h:197:9: error: reference to ‘writable’ is ambiguous writable::strings names(j.size()); ^~~~~~~~ In file included from rjsoncons.cpp:1:0: /home/ignatius/R/x86_64-pc-linux-gnu-library/4.3/cpp11/include/cpp11/declarations.hpp:14:39: note: candidates are: namespace writable = cpp11::cpp11::writable; namespace writable = ::cpp11::writable; ^ In file included from /home/ignatius/R/x86_64-pc-linux-gnu-library/4.3/cpp11/include/cpp11/list.hpp:10:0, from /home/ignatius/R/x86_64-pc-linux-gnu-library/4.3/cpp11/include/cpp11/data_frame.hpp:12, from /home/ignatius/R/x86_64-pc-linux-gnu-library/4.3/cpp11/include/cpp11.hpp:7, from /home/ignatius/R/x86_64-pc-linux-gnu-library/4.3/cpp11/include/cpp11/declarations.hpp:13, from rjsoncons.cpp:1: /home/ignatius/R/x86_64-pc-linux-gnu-library/4.3/cpp11/include/cpp11/r_vector.hpp:44:11: note: namespace cpp11::writable { } namespace writable { ^~~~~~~~ In file included from rjsoncons.cpp:8:0: j_as.h:202:13: error: ‘names’ was not declared in this scope names[i] = it->key(); ^~~~~ j_as.h:203:13: error: ‘value’ was not declared in this scope value[i] = as_r(it->value()); ^~~~~ j_as.h:206:9: error: ‘value’ was not declared in this scope value.names() = names; ^~~~~ j_as.h:206:25: error: ‘names’ was not declared in this scope value.names() = names; ^~~~~ /usr/lib/R/etc/Makeconf:200: recipe for target 'rjsoncons.o' failed make: *** [rjsoncons.o] Error 1 ERROR: compilation failed for package ‘rjsoncons’ * removing ‘/home/ignatius/R/x86_64-pc-linux-gnu-library/4.3/rjsoncons’ The downloaded source packages are in ‘/tmp/Rtmppa0z3X/downloaded_packages’ Warning message: In install.packages("rjsoncons", repos = "https://CRAN.R-project.org") : installation of package ‘rjsoncons’ had non-zero exit status
内容的提问来源于stack exchange,提问作者Ignatius Pang
相关产品推荐
相关产品推荐

