[英]How would I instruct extconf.rb to use additional g++ optimization flags, and which are advisable?
I'm using Rice to write a C++ extension for a Ruby gem.我正在使用Rice为 Ruby gem 编写 C++ 扩展。 The extension is in the form of a shared object (.so) file.扩展名采用共享对象 (.so) 文件的形式。
This requires 'mkmf-rice' instead of 'mkmf', but the two (AFAIK) are pretty similar.这需要“mkmf-rice”而不是“mkmf”,但两者(AFAIK)非常相似。
By default, the compiler uses the flags -g -O2
.默认情况下,编译器使用标志-g -O2
。 Personally, I find this kind of silly, since it's hard to debug with any optimization enabled.就我个人而言,我觉得这种做法很愚蠢,因为在启用任何优化的情况下都很难进行调试。 I've resorted to editing the Makefile to take out the flags I don't like (eg, removing -fPIC -shared
when I need to debug using main()
instead of Ruby's hooks).我已经通过编辑 Makefile 来删除我不喜欢的标志(例如,当我需要使用main()
而不是 Ruby 的钩子进行调试时,删除-fPIC -shared
)。
But I figure there's got to be a better way.但我认为必须有更好的方法。 I know I can just do我知道我能做到
$CPPFLAGS += " -DRICE"
to add additional flags.添加其他标志。 But how do I remove things without editing the Makefile directly?但是如何在不直接编辑 Makefile 的情况下删除内容?
A secondary question: what optimizations are safe for shared objects loaded by Ruby?第二个问题:对于 Ruby 加载的共享对象,哪些优化是安全的? Can I do things like -funroll-loops
?我可以做-funroll-loops
类的事情吗? What do you all recommend?大家推荐什么?
It's a scientific computing project, so the faster the better.这是一个科学计算项目,所以越快越好。 Memory is not much of an issue.内存不是什么大问题。
To define you use定义你使用
-D name=definition
like you do in your example:就像您在示例中所做的那样:
$CPPFLAGS += " -DRICE"
-U name -U 名字
Cancel any previous definition of name, either built in or provided with a -D option.取消任何以前的 name 定义,无论是内置的还是带有 -D 选项的。
$CPPFLAGS += " -URICE"
Although I'm not sure if it'll help with undefining -O2 like you want it.尽管我不确定它是否有助于像您想要的那样取消定义 -O2。
The quick and dirty way is to append -O0 to CXXFLAGS, which will turn off optimization.快速而肮脏的方法是将 -O0 附加到 CXXFLAGS,这将关闭优化。 Later options will override earlier ones.稍后的选项将覆盖较早的选项。
As far as safety for a plugin, you should be able to do anything that doesn't affect the ABI.至于插件的安全性,您应该能够做任何不影响 ABI 的事情。 Without testing, I don't see why -funroll would.没有测试,我不明白为什么 -funroll 会。 Of course, safe does not imply better.当然,安全并不意味着更好。 As noted by the man page, "-funroll-loops makes code larger, and may or may not make it run faster."正如手册页所述,“-funroll-loops 使代码更大,并且可能会也可能不会使其运行得更快。”
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.