问题描述
我正在构建一个用于Python的C ++扩展。我看到这个警告是在编译过程中产生的 - 当一个类型为:
python setup.py build_ext -i
造成这种情况的原因是什么,以及如何解决它?
顺便说一下,这是我的设置文件的副本:
#!/ usr / bin / env python
setup.py文件,用于SWIG示例
$ b $ from distutils.core import setup,Extension
example_module = Extension('_ foolib',
sources = ['example_wrap.cxx',
'../wrapper++/src/Foo.cpp'
],
库= [foopp]
)
setup(name ='foolib',
version ='0.1',
author =Me,Myself and I,
description =例子,
ext_m odules = [example_module],
py_modules = [example],
)
我在Ubuntu上使用gcc 4.4.3
我可以回答部分问题,为什么你会得到消息。
构建过程中的某些内容是使用 -Wstrict-prototypes
选项在C ++源文件上调用gcc, 。对于C和Objective-C,这会导致编译器警告未声明参数类型的旧式函数声明。
对于C ++,此选项不会没有道理; (原型是强制性的)。
(我不知道为什么消息提到Ada; - Wstrict-prototypes
对于Ada而言比C ++更不明智,这不是什么大问题,但我已经提交了,截至2015-12-06标记为RESOLVED / FIXED。)
解决方案应该是删除来自调用gcc的 -Wstrict-prototypes
选项。但是,由于您不是直接调用gcc,所以很难知道如何做到这一点。
我可以使用设置重现警告.py
,手动创建一个虚拟 example_wrap.cxx
文件:
%python setup.py build_ext -i
正在运行build_ext
建立'_foolib'扩展
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:命令行选项-Wstrict-prototypes适用于Ada / C / ObjC,但不适用于C ++
...
$ b $所以它可能是Python的 build_ext
中的一个小错误。
但是,因为它只是一个警告,而不是一个致命的错误,我会说你可以放心地忽略它。 gcc对无意义的选项提出警告,但它只是忽略它。
编辑:
通过Python-2.7.2来源,这部分 configure.in
可能是罪魁祸首:
case $ gcc in
yes)
if test$ CC!='g ++';那么
STRICT_PROTO = - Wstrict-prototypes
fi
假设这是在使用 build_ext
时调用的。)
它打开 -Wstrict-原型
选项仅当编译器 not 被调用为 g ++
- 但在你的情况下它使用 gcc
命令编译C ++源代码。并且在 Lib / distutils / command / build_ext.py
中, build_extension()
不关注源文件当调用 self.compiler.compile()
时,仅在调用 self.compiler.link_shared_object()
时使用语言。 (这看起来很奇怪;对于gcc以外的编译器,你不一定能够使用相同的命令来编译C和C ++ - 并且使用 g ++ $ c $更合理c>命令,即使你没有链接。)
更新:提交了Python错误报告:,并将其作为这一个的副本关闭:,它在我写这篇文章时仍然是打开的。
但正如我所说,这只是一个警告而你可以安全地忽略它。也许Python维护者可以使用上述信息来解决未来版本中的问题。
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 am using gcc 4.4.3 on Ubuntu
I can answer part of the question, why you're getting the message.
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.
For C++, this option doesn't make sense; such declarations aren't even allowed by the language (prototypes are mandatory).
(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.)
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.
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++
...
So it's probably a minor bug in Python's build_ext
.
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.
EDIT:
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 assuming that's invoked when using build_ext
.)
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.)
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.
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:warning:命令行选项“-Wstrict-prototypes”适用于Ada / C / ObjC但不适用于C ++的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!