cc1plus:警告:命令行选项" -Wstrict-prototypes& quot;对Ada / C / ObjC有效,但对C ++无效 [英] cc1plus: warning: command line option "-Wstrict-prototypes" is valid for Ada/C/ObjC but not for C++
问题描述
我正在构建用于Python的C ++扩展。我在编译过程中看到此警告-类型为
I am building a C++ extension for use in Python. I am seeing this warning being generated during the compilation process - when a type:
python setup.py build_ext -i
是什么原因引起的,如何解决?
What is causing it, and how do I fix it?
顺便说一句,这是我的安装文件的副本:
BTW, here is a copy of my setup file:
#!/usr/bin/env python
"""
setup.py file for SWIG example
"""
from distutils.core import setup, Extension
example_module = Extension('_foolib',
sources=['example_wrap.cxx',
'../wrapper++/src/Foo.cpp'
],
libraries=["foopp"]
)
setup (name = 'foolib',
version = '0.1',
author = "Me, Myself and I",
description = """Example""",
ext_modules = [example_module],
py_modules = ["example"],
)
I在Ubuntu上使用gcc 4.4.3
I am using gcc 4.4.3 on Ubuntu
推荐答案
我可以回答部分问题,为什么会收到消息。
I can answer part of the question, why you're getting the message.
构建过程中的某些事情是使用选项 -Wstrict-prototypes
在C ++源文件上调用gcc。对于C和Objective-C,这会导致编译器警告未声明参数类型的老式函数声明。
Something in your build process is invoking gcc on a C++ source file with the option -Wstrict-prototypes
. For C and Objective-C, this causes the compiler to warn about old-style function declarations that don't declare the types of arguments.
对于C ++,此选项不会没有道理;
For C++, this option doesn't make sense; such declarations aren't even allowed by the language (prototypes are mandatory).
(我不知道为什么消息中提到Ada; -严格的原型
对Ada的意义远不及对C ++的意义。虽然这没什么大不了的,但是我已经提交了此错误报告,自2015年12月6日起标记为已解决/已修复。)
(I don't know why the message mentions Ada; -Wstrict-prototypes
makes even less sense for Ada than for C++. It's not a huge deal, but I've submitted this bug report, marked as RESOLVED/FIXED as of 2015-12-06.)
解决方法是删除gcc调用的 -Wstrict-prototypes
选项。但是由于您不是直接调用gcc,所以很难知道该怎么做。
The solution should be to remove the -Wstrict-prototypes
option from the invocation of gcc. But since you're not invoking gcc directly, it's difficult to know how to do that.
我能够使用您的设置重现警告.py
,在手动创建虚拟 example_wrap.cxx
文件后:
I was able to reproduce the warning using your setup.py
, after manually creating a dummy example_wrap.cxx
file:
% python setup.py build_ext -i
running build_ext
building '_foolib' extension
gcc -pthread -fno-strict-aliasing -DNDEBUG -g -fwrapv -O2 -Wall -Wstrict-prototypes -fPIC -I/usr/include/python2.7 -c example_wrap.cxx -o build/temp.linux-i686-2.7/example_wrap.o
cc1plus: warning: command line option "-Wstrict-prototypes" is valid for Ada/C/ObjC but not for C++
...
所以这可能是Python build_ext
中的一个小错误。
So it's probably a minor bug in Python's build_ext
.
但是由于这只是一个警告,而不是致命错误,我想您可以放心地忽略它。 gcc会警告无意义的选项,但它只会忽略它。
But since it's only a warning, not a fatal error, I'd say you can safely ignore it. gcc warns about the meaningless option, but then it just ignores it.
编辑:
通过Python-2.7.2的源代码, configure.in
的这一部分可能是罪魁祸首:
Looking through the Python-2.7.2 sources, this section of configure.in
might be the culprit:
case $GCC in
yes)
if test "$CC" != 'g++' ; then
STRICT_PROTO="-Wstrict-prototypes"
fi
(I' m假定是在使用 build_ext
时调用的。)
(I'm assuming that's invoked when using build_ext
.)
打开 -Wstrict-仅当不是作为
选项,但在您的情况下,它使用的是 g ++
调用编译器时,才选择prototypes gcc
命令来编译C ++源代码。在 Lib / distutils / command / build_ext.py
中, build_extension()
并不关注源文件调用 self.compiler.compile()
时的语言,仅当调用 self.compiler.link_shared_object()
时。 (这似乎很奇怪;对于gcc以外的编译器,您不一定能够使用相同的命令来编译C和C ++,并且使用 g ++ $ c $更有意义c>命令,即使您未链接也是如此。)
It turns on the -Wstrict-prototypes
option only if the compiler is not being invoked as g++
-- but in your case it's using the gcc
command to compile C++ source code. And in Lib/distutils/command/build_ext.py
, build_extension()
doesn't pay attention to the source file language when invoking self.compiler.compile()
, only when invoking self.compiler.link_shared_object()
. (Which seems odd; for compilers other than gcc, you wouldn't necessarily be able to use the same command to compile C and C++ -- and it makes more sense to use the g++
command anyway, even if you're not linking.)
更新:提交了Python错误报告: https://bugs.python.org/issue9031 ,并作为此副本的副本关闭: https ://bugs.python.org/issue1222585 ,在我撰写本文时仍会打开。
UPDATE: A Python bug report was submitted: https://bugs.python.org/issue9031, and closed as a duplicate of this one: https://bugs.python.org/issue1222585, which is still open as I write this.
但是正如我所说,这只是一个警告,你可以放心地忽略它。也许Python维护人员可以使用以上信息在将来的版本中解决该问题。
But as I said, it's only a warning and you can probably safely ignore it. Perhaps the Python maintainers can use the above information to fix the problem in a future release.
这篇关于cc1plus:警告:命令行选项" -Wstrict-prototypes& quot;对Ada / C / ObjC有效,但对C ++无效的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!