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

标签 c++ ruby g++ warnings ruby-c-extension

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

require "mkmf"
$libs += " -lstdc++ "
create_makefile("file_name")

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

cc1plus: warning: command line option "-Wdeclaration-after-statement" is valid for C/ObjC but not for C++

我读到它没有害处,但是有没有办法避免这个警告?有人有同样的问题here , 但找不到解决方案。

最佳答案

在你的 extconf.rb 中试试这个:

$warnflags.gsub!('-Wdeclaration-after-statement', '') if $warnflags

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

更新:

这可能更好:

CONFIG['warnflags'].gsub!('-Wdeclaration-after-statement', '')

$warnflags 从此填充,但这不需要 if $warnflags 用于 < 1.9.3。

关于c++ - 带有 g++ 的不需要的警告消息,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10164987/

相关文章:

c++ - 如何保护进程免受 writeprocessmemory 的影响?

c++ - 根据其他模板参数指定返回类型

ruby - 为 ruby​​ 1.9 设置全局默认编码

c++ - g++:Ubuntu 发行版升级后,我的所有代码都不会链接

c++ - Boost 并发库在使用 GNU C++/LLVM C++ 编译时表现不同

android - Android 和 iOS 中的 C/C++ 标准库在哪里?

c++ - OpenGL 中的故障面部变形目标动画 (C++)

ruby-on-rails - 安装 rmovie gem 时无法构建 gem 原生扩展

ruby - Ruby 中的单竖线和等号线是什么意思?

g++ - Mingw32 std::isnan 与 -ffast-math