带有g ++的不需要的警告消息

saw*_*awa 2 c++ ruby warnings g++ ruby-c-extension

我正在尝试为Ruby编写c ++扩展.除了主文件,我有一个文件extconf.rb:

require "mkmf"
$libs += " -lstdc++ "
create_makefile("file_name")
Run Code Online (Sandbox Code Playgroud)

并且,在做完之后ruby extconf.rb,当我尝试g++通过键入来编译它时make,我收到警告:

cc1plus: warning: command line option "-Wdeclaration-after-statement" is valid for C/ObjC but not for C++
Run Code Online (Sandbox Code Playgroud)

我读到它没有害处,但有没有办法避免这种警告?有同样的问题一个人在这里,但解决方案无法找到.

mat*_*att 9

试试这个extconf.rb:

$warnflags.gsub!('-Wdeclaration-after-statement', '') if $warnflags
Run Code Online (Sandbox Code Playgroud)

if $warnflags是需要的,因为mkmf在红宝石1.9.3改变; 没有它你会得到undefined method `gsub!' for nil:NilClass如果你尝试在Ruby 1.9.2上构建.您不应该在1.9.2中获得c ++警告:Ruby使用的默认警告在1.9.3中已更改,并且已添加这些警告.

更新:

这可能更好:

CONFIG['warnflags'].gsub!('-Wdeclaration-after-statement', '')
Run Code Online (Sandbox Code Playgroud)

$warnflags从中填充,但这不需要if $warnflagsfor <1.9.3.