This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: warning '"_POSIX_C_SOURCE" redefined' when include Python.h
Type: Stage:
Components: Extension Modules Versions: Python 2.3
process
Status: closed Resolution: not a bug
Dependencies: Superseder:
Assigned To: Nosy List: Jonathan.Wakely, eugene_beast, loewis
Priority: normal Keywords:

Created on 2004-10-13 05:06 by eugene_beast, last changed 2022-04-11 14:56 by admin. This issue is now closed.

Messages (5)
msg22666 - (view) Author: Eugene Sizikov (eugene_beast) Date: 2004-10-13 05:06
"""
In file included from /usr/include/python2.3/Python.h:8,
                 from script.h:21,
                 from server.cpp:23:
/usr/include/python2.3/pyconfig.h:847:1: warning:
"_POSIX_C_SOURCE" redefined
In file included from
/usr/lib/gcc/i386-redhat-linux/3.4.0/../../../../include/c++/3.4.0/i386-redhat-linux/bits/os_defines.h:39,
                 from
/usr/lib/gcc/i386-redhat-linux/3.4.0/../../../../include/c++/3.4.0/i386-redhat-linux/bits/c++config.h:35,
                 from
/usr/lib/gcc/i386-redhat-linux/3.4.0/../../../../include/c++/3.4.0/iostream:44,
                 from server.cpp:18:
/usr/include/features.h:131:1: warning: this is the
location of the previous definition
""'

The above message is shown whenever program (extending
or embedding python with C/C++) using Python.h was
compilled.

OS: Fedora Core 2
compiller: GCC 3.4.0
libc: glibc-2.3
Python: 2.3.3
msg22667 - (view) Author: Martin v. Löwis (loewis) * (Python committer) Date: 2004-10-19 19:39
Logged In: YES 
user_id=21627

This is a bug in your program. See

http://docs.python.org/api/includes.html
msg22668 - (view) Author: Eugene Sizikov (eugene_beast) Date: 2004-10-20 00:00
Logged In: YES 
user_id=126917

But why not made it more compliant in Python.h :

#ifndef _POSIX_C_SOURCE
#define _POSIX_C_SOURCE
#endif

???
msg22669 - (view) Author: Martin v. Löwis (loewis) * (Python committer) Date: 2004-10-20 06:26
Logged In: YES 
user_id=21627

Python itself and Python extensions must be compiled with
precisely the same settings, so taking some other setting of
_POSIX_C_SOURCE may cause binary incompatibility.

If you include Python.h first, as you should,
_POSIX_C_SOURCE will not be defined, so the #ifndef should
not have any effect except in broken extension modules.
msg188842 - (view) Author: Jonathan Wakely (Jonathan.Wakely) Date: 2013-05-10 15:37
Insisting on including Python.h first is just broken.

GNU libc's /usr/include/features.h will override it anyway when _GNU_SOURCE is defined:

# undef  _POSIX_C_SOURCE
# define _POSIX_C_SOURCE    200809L
# undef  _XOPEN_SOURCE
# define _XOPEN_SOURCE  700

So if you define _GNU_SOURCE ( which happens automatically when using G++) the annoying defines in pyconfig.h are overridden anyway, so why not just only define them if not already defined?

Either you include Python.h first and its settings get ignored by glibc, or you don't include it first and you get annoying warnings.
History
Date User Action Args
2022-04-11 14:56:07adminsetgithub: 41011
2013-05-10 15:37:26Jonathan.Wakelysetnosy: + Jonathan.Wakely
messages: + msg188842
2004-10-13 05:06:02eugene_beastcreate