I am trying to write a c++ extension for Ruby. In addition to the main file, I have a file extconf.rb:
require "mkmf"
$libs += " -lstdc++ "
create_makefile("file_name")
and, after doing ruby extconf.rb, when I try to compile it with g++ by typing make, I get the warning:
cc1plus: warning: command line option "-Wdeclaration-after-statement" is valid for C/ObjC but not for C++
I read that it is not harmful, but is there a way to avoid this warning? There is a person with the same problem here, but the solution cannot be found.
Try this in your extconf.rb:
$warnflags.gsub!('-Wdeclaration-after-statement', '') if $warnflags
the if $warnflags is needed because mkmf changed in Ruby 1.9.3; without it you'll get undefined method `gsub!' for nil:NilClass if you try to build on Ruby 1.9.2. You shouldn’t get the c++ warning in 1.9.2 though: the default warnings Ruby uses changed in 1.9.3 and these have been added.
Update:
This is probably better:
CONFIG['warnflags'].gsub!('-Wdeclaration-after-statement', '')
$warnflags gets populated from this, but this doesn't need the if $warnflags for < 1.9.3.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With