如何使用Rcpp和内联设置g ++编译器标志? [英] How to set g++ compiler flags using Rcpp and inline?

查看:185
本文介绍了如何使用Rcpp和内联设置g ++编译器标志?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想设置 -std = c ++ 0x ,使用Rcpp与内联。

I want to set -std=c++0x, using Rcpp with inline.

R:使用内联包时的C ++优化标记,但是

我试过:

settings=getPlugin("Rcpp")
settings$Makevars[length(settings$Makevars)+1] = "CXXFLAGS = $(CXXFLAGS) -std=c++0x"
fun=cxxfunction(signature(x_ ="numeric"),src,plugin="Rcpp",settings=settings,verbose=2);

但是详细输出显示它忽略了。我也尝试过CFLAGS,但不包括现有的值,但没有效果。

But the verbose output shows it is ignoring that. I also tried with CFLAGS, and without including existing value, but no effect.

推荐答案

从Dirk Eddelbuettel,我已经这样做:

After some source code study, and a hint from Dirk Eddelbuettel, I've worked this out:

settings$env$PKG_CXXFLAGS='-std=c++0x'

您可以使用相同的方式设置PKG_CPPFLAGS。

You can set PKG_CPPFLAGS the same way.

这里是一个完整和更加健壮的例子:

Here is a complete and more robust example:

library(inline)

src='
using namespace Rcpp;
std::vector<const char*> test={"Hello","World","!!!"};
return wrap(test);
'

settings=getPlugin("Rcpp")
settings$env$PKG_CXXFLAGS=paste('-std=c++0x',settings$env$PKG_CXXFLAGS,sep=' ')
fun=cxxfunction(signature(),src,plugin="Rcpp",settings=settings)

Sys.unsetenv('PKG_CXXFLAGS')

print(fun())

unsetenv()是cxxfunction应该已经做了(IMHO)的东西。目前它将向环境中添加变量,但不会删除它们。所以,没有unsetenv()调用,如果你以后再次运行cxxfunction,但所有默认值,你以前设置的任何CXXFLAGS将被使用。这可能没关系,或者它可能会产生令人惊讶的结果。 (假设您使用PKG_CXXFLAGS为您自己的代码设置-Wall -Werror,但后来的代码链接到第三方库,并拒绝使用这些选项进行编译。)

The unsetenv() is something cxxfunction should already be doing (IMHO). Currently it will add variables to the environment, but not remove them after. So, without the unsetenv() call, if you later ran cxxfunction again, but with all defaults, any CXXFLAGS you had earlier set would get used. This might not matter, or it might give surprising results. (Imagine if your were using PKG_CXXFLAGS to set '-Wall -Werror' for your own code, but later code links to a 3rd party library and refuses to compile with those options.)

这篇关于如何使用Rcpp和内联设置g ++编译器标志?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆