包含Rcpp.h时未定义的引用错误 [英] Undefined reference errors when including Rcpp.h
问题描述
我使用的是64位Ubuntu,我正在尝试编写C ++。
我发现如果使用 #include
,我甚至不需要致电在R命名空间中的任何函数,并且我已经收到未激活的引用错误:
obj / xo:在函数`Rcpp :: Rstreambuf< true> :: xsputn(char const *,long)':
/usr/local/lib/R/site-library/Rcpp/include/Rcpp/iostream/Rstreambuf.h:61:undefined reference to `Rprintf'
obj / xo:函数`Rcpp :: Rstreambuf< false> :: xsputn(char const *,long)':
/ usr / local / lib / R / site-library / Rcpp / include / Rcpp / iostream / Rstreambuf.h:65:未定义引用'REprintf'
obj / xo:在函数`Rcpp :: Rstreambuf< true> :: overflow(int)'中:
/usr/local/lib/R/site-library/Rcpp/include/Rcpp/iostream/Rstreambuf.h:70:对'Rprintf'
obj / xo的未定义引用:函数`Rcpp :: Rstreambuf > ; :: overflow(int)':
/usr/local/lib/R/site-library/Rcpp/include/Rcpp/iostream/Rstreambuf.h:74:未定义的引用'REprintf
obj / xo:函数`Rcpp :: Rstreambuf< true> :: sync()':
/ usr / local / lib / R / site-library / Rcpp / include / Rcpp / iostream /在函数`Rcpp :: Rstreambuf< false> :: sync()'中:
/ usr / local / lib / R / site-library / Rcpp / include / Rcpp / iostream / Rstreambuf.h:83:对`R_FlushConsole'
的未定义引用
我已经安装了r-base和r-base-dev。我通过以root身份运行R来安装Rcpp,并执行了 install.package(Rcpp)
使用g ++与 -I / usr / local / lib / R / site-library / Rcpp / include
我在这里错过了什么?感谢您的回复。
只要拉 Rcpp
标题是不够的。您还需要R标头并链接到R的库。您可以使用例如 R CMD SHLIB
为您做到这一点。
然而,我建议你:
- 创建一个包有
LinkingTo:Rcpp
等...(请参阅Rcpp的文档)。 - 在
.cpp
文件中使用sourceCpp
。请参阅?sourceCpp
I am using 64bit Ubuntu, and I am trying to write C++.
I discovered if I use #include <Rcpp.h>
, I don't even need to call any functions in the R namespace, and I would already receive undefired reference errors:
obj/x.o: In function `Rcpp::Rstreambuf<true>::xsputn(char const*, long)':
/usr/local/lib/R/site-library/Rcpp/include/Rcpp/iostream/Rstreambuf.h:61: undefined reference to `Rprintf'
obj/x.o: In function `Rcpp::Rstreambuf<false>::xsputn(char const*, long)':
/usr/local/lib/R/site-library/Rcpp/include/Rcpp/iostream/Rstreambuf.h:65: undefined reference to `REprintf'
obj/x.o: In function `Rcpp::Rstreambuf<true>::overflow(int)':
/usr/local/lib/R/site-library/Rcpp/include/Rcpp/iostream/Rstreambuf.h:70: undefined reference to `Rprintf'
obj/x.o: In function `Rcpp::Rstreambuf<false>::overflow(int)':
/usr/local/lib/R/site-library/Rcpp/include/Rcpp/iostream/Rstreambuf.h:74: undefined reference to `REprintf'
obj/x.o: In function `Rcpp::Rstreambuf<true>::sync()':
/usr/local/lib/R/site-library/Rcpp/include/Rcpp/iostream/Rstreambuf.h:79: undefined reference to `R_FlushConsole'
obj/x.o: In function `Rcpp::Rstreambuf<false>::sync()':
/usr/local/lib/R/site-library/Rcpp/include/Rcpp/iostream/Rstreambuf.h:83: undefined reference to `R_FlushConsole'
I have installed r-base and r-base-dev. I installed Rcpp by running R as root and did a install.package("Rcpp")
I compile the C++ program using g++ with -I/usr/local/lib/R/site-library/Rcpp/include
What am I missing here? Thanks for any replies.
Just pulling Rcpp
headers is not enough. You also need R headers and linking against R's library. You could use e.g. R CMD SHLIB
to do this for you.
However, I'd suggest you either:
- create a package that has
LinkingTo: Rcpp
etc ... (see Rcpp's documentation). - use
sourceCpp
on your.cpp
file. See?sourceCpp
这篇关于包含Rcpp.h时未定义的引用错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!