cc1plus: warning: command line option -Wstrict-prototypes is valid for Ada/C/ObjC but not for C++

2024/11/18 0:39:09

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, Extensionexample_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

Answer

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++' ; thenSTRICT_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.

https://en.xdnf.cn/q/26513.html

Related Q&A

Any way to add a new line from a string with the \n character in flask?

I was playing around with flask when I came across an odd problem with the \n character. it dosent seem to have an effect in my browser, I tried putting in there but it didnt work, any ideas?from fla…

Get list of Cache Keys in Django

Im trying to understand how Django is setting keys for my views. Im wondering if theres a way to just get all the saved keys from Memcached. something like a cache.all() or something. Ive been trying t…

numpy: multiply arrays rowwise

I have those arrays:a = np.array([[1,2],[3,4],[5,6],[7,8]])b = np.array([1,2,3,4])and I want them to multiply like so:[[1*1, 2*1], [3*2, 4*2], [5*3, 6*3], [7*4, 8*4]]... basically out[i] = a[i] * b[i],…

django post_save signals on update

I am trying to set up some post_save receivers similar to the following: @receiver(post_save, sender=Game, dispatch_uid=game_updated) def game_updated(sender, **kwargs):DO SOME STUFF HEREMyPick.objects…

Fastest way to pack a list of floats into bytes in python

I have a list of say 100k floats and I want to convert it into a bytes buffer.buf = bytes() for val in floatList:buf += struct.pack(f, val) return bufThis is quite slow. How can I make it faster using …

PyPI is slow. How do I run my own server?

When a new developer joins the team, or Jenkins runs a complete build, I need to create a fresh virtualenv. I often find that setting up a virtualenv with Pip and a large number (more than 10) of requi…

How to suppress the deprecation warnings in Django?

Every time Im using the django-admin command — even on TAB–completion — it throws a RemovedInDjango19Warning (and a lot more if I use the test command). How can I suppress those warnings?Im using D…

whats the fastest way to find eigenvalues/vectors in python?

Currently im using numpy which does the job. But, as im dealing with matrices with several thousands of rows/columns and later this figure will go up to tens of thousands, i was wondering if there was …

Python Patch/Mock class method but still call original method

I want to use patch to record all function calls made to a function in a class for a unittest, but need the original function to still run as expected. I created a dummy code example below:from mock im…

Daemon vs Upstart for python script

I have written a module in Python and want it to run continuously once started and need to stop it when I need to update other modules. I will likely be using monit to restart it, if module has crashed…