如何设置g++使用 Rcpp 和内联的编译器标志?
我想设置 -std=c++0x
,使用 Rcpp 和内联。
我看到 R:使用内联包时的 C++ 优化标志但不想进行系统范围的更改,所以我尝试了 Dirk 答案中的选项 2。
我尝试过:
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,并且不包含现有值,但没有效果。
I want to set -std=c++0x
, using Rcpp with inline.
I saw R: C++ Optimization flag when using the inline package but don't want to make a system-wide change, so I was trying option 2 in Dirk's answer.
I tried:
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);
But the verbose output shows it is ignoring that. I also tried with CFLAGS, and without including existing value, but no effect.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
经过一些源代码研究以及 Dirk Eddelbuettel 的提示,我已经解决了这个问题:
您可以以相同的方式设置 PKG_CPPFLAGS 。
这是一个完整且更强大的示例:
paste()
确保插件中是否已有任何设置,然后它们会被保留。unsetenv()
是cxxfunction
应该已经在做的事情(恕我直言)。目前它会将变量添加到环境中,但之后不会将其删除。因此,如果没有unsetenv()
调用,如果您稍后再次运行cxxfunction
,但使用所有默认值,您之前设置的任何CXXFLAGS
都会得到用过的。这可能并不重要,或者可能会产生令人惊讶的结果。 (想象一下,如果您使用PKG_CXXFLAGS
为自己的代码设置-Wall -Werror
,但后来的代码链接到第 3 方库并拒绝使用这些选项进行编译。)After some source code study, and a hint from Dirk Eddelbuettel, I've worked this out:
You can set
PKG_CPPFLAGS
the same way.Here is a complete and more robust example:
The
paste()
makes sure if there were any settings already in the plugin then they are preserved.The
unsetenv()
is somethingcxxfunction
should already be doing (IMHO). Currently it will add variables to the environment, but not remove them after. So, without theunsetenv()
call, if you later rancxxfunction
again, but with all defaults, anyCXXFLAGS
you had earlier set would get used. This might not matter, or it might give surprising results. (Imagine if your were usingPKG_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.)