classification
Title: hypot define in pyconfig.h clashes with g++'s cmath
Type: compile error Stage:
Components: Windows Versions: Python 3.3
process
Status: open Resolution:
Dependencies: Superseder:
Assigned To: Nosy List: Kay.Hayen, brian.curtin, eudoxos, loewis, mark.dickinson, pas, pokulo, schmir, thewtex
Priority: normal Keywords:

Created on 2011-03-15 23:39 by schmir, last changed 2017-03-28 19:49 by thewtex.

Pull Requests
URL Status Linked Edit
PR 880 open thewtex, 2017-03-28 19:48
Messages (14)
msg131067 - (view) Author: Ralf Schmitt (schmir) Date: 2011-03-15 23:39
The following program

#include <Python.h>
#include <cmath>

results in the following error when compiled with g++ and -std=gnu++0x:

$ g++ -std=gnu++0x -c t.cc -I /c/Python27/Include
In file included from c:\mingw64\bin\../lib/gcc/x86_64-w64-mingw32/4.5.1/include/c++/cmath:629:0,
                 from t.cc:2:
c:\mingw64\bin\../lib/gcc/x86_64-w64-mingw32/4.5.1/include/c++/tr1_impl/cmath:203:11: error: '::hypot' has not been declared

The problem is, that pyconfig.h has the following define:

#define hypot _hypot

It should probably just be removed when using gcc.
msg172674 - (view) Author: Petri Lehtinen (petri.lehtinen) * (Python committer) Date: 2012-10-11 18:59
Cannot reproduce, and cannot find the define in pyconfig.h. It's in PC/pyconfig.h, but shouldn't affect compiling with gcc.
msg172675 - (view) Author: Ralf Schmitt (schmir) Date: 2012-10-11 19:02
Sorry, if I haven't been clear enough. This happens on windows when compiling extensions with "g++ -std=gnu++0x ..."
msg172683 - (view) Author: Petri Lehtinen (petri.lehtinen) * (Python committer) Date: 2012-10-11 19:44
On MinGW? I'm not a Windows user, but IIRC building extensions with gcc on MinGW has many problems and isn't officially supported.
msg172684 - (view) Author: Ralf Schmitt (schmir) Date: 2012-10-11 19:52
yes, mingw. it may have some problems and this is one of them!
msg174157 - (view) Author: Václav Šmilauer (eudoxos) * Date: 2012-10-29 22:45
I would like to second Ralf here. I am having the same issue with mingw's gcc 4.7 and -std=c++11.
msg174197 - (view) Author: Mark Dickinson (mark.dickinson) * (Python committer) Date: 2012-10-30 10:16
I think there's something generally smelly about the way hypot is handled;  this isn't the only hypot-related build issue that's turned up.  I'm wondering whether the code can be reworked to deal with hypot in the same way that functions like log1p, etc. are dealt with in the math module---i.e., define a _Py_hypot wrapper function, and use that everywhere internally.  One difference is that log1p is only used in cmath and math, while hypot is also needed in the Python core.
msg174198 - (view) Author: Václav Šmilauer (eudoxos) * Date: 2012-10-30 10:19
Just for the record: a workaround (mentioned at http://boost.2283326.n4.nabble.com/Boost-Python-Compile-Error-s-GCC-via-MinGW-w64-td3165793.html#a3166760) is to always include <cmath> before <Python.h>.
msg174366 - (view) Author: Mark Dickinson (mark.dickinson) * (Python committer) Date: 2012-10-31 20:33
Is this also an issue for Python 3.x?
msg174397 - (view) Author: Martin v. Löwis (loewis) * (Python committer) Date: 2012-11-01 10:41
In general, including standard library headers before including Python.h is not recommended, since it may break binary compatibility across object files. So the proposed work-around may also cause harm.
msg175568 - (view) Author: Václav Šmilauer (eudoxos) * Date: 2012-11-14 13:17
Martin, I know it is not a proper fix. OTOH, Python is not the only project which "recommends" its header be included as first.

I don't know if it is an issue for Python 3.x; will try to test that. This bug, though, is clearly reported about Python 2.7, which IS in bug-fix mode.
msg201101 - (view) Author: Heinrich Kießling (pokulo) Date: 2013-10-24 08:56
uning python 3.3 mingw4.8 both -std=gnu++0x and -std=c++11 cause still the same error.
msg272475 - (view) Author: Kay Hayen (Kay.Hayen) Date: 2016-08-11 18:48
This also affects Python2.7.12 on Windows with latest MinGW. I think something similar needs to be added for GCC version check:

/* VS 2010 and above already defines hypot as _hypot */
#if _MSC_VER < 1600
#define hypot _hypot
#endif

Not sure which gcc version first had that, but 6.1 definitely does.

Yours,
Kay
msg290754 - (view) Author: Matthew McCormick (thewtex) * Date: 2017-03-28 19:49
I have created a pull request for this issue,

  https://github.com/python/cpython/pull/880

that addresses extension builds for both MinGWPy and the Microsoft Visual C++ Compiler for Python 2.7.
History
Date User Action Args
2017-03-28 19:49:47thewtexsetnosy: + thewtex
messages: + msg290754
2017-03-28 19:48:57thewtexsetpull_requests: + pull_request780
2016-08-16 06:22:00petri.lehtinensetnosy: - petri.lehtinen
2016-08-15 13:24:01passetnosy: + pas
2016-08-11 18:48:54Kay.Hayensetnosy: + Kay.Hayen
messages: + msg272475
2013-10-24 09:54:49tim.goldensetnosy: - tim.golden
2013-10-24 08:56:56pokulosetnosy: + pokulo

messages: + msg201101
versions: + Python 3.3, - Python 2.7
2012-11-14 13:17:31eudoxossetmessages: + msg175568
2012-11-01 10:41:27loewissetmessages: + msg174397
2012-10-31 20:33:35mark.dickinsonsetmessages: + msg174366
2012-10-30 10:19:42eudoxossetmessages: + msg174198
2012-10-30 10:16:11mark.dickinsonsetmessages: + msg174197
2012-10-30 09:33:59mark.dickinsonsetnosy: + mark.dickinson
2012-10-29 22:45:34eudoxossetnosy: + eudoxos
messages: + msg174157
2012-10-11 19:52:28schmirsetmessages: + msg172684
2012-10-11 19:44:59petri.lehtinensetnosy: + loewis, tim.golden, brian.curtin
messages: + msg172683
components: + Windows, - None
2012-10-11 19:02:20schmirsetstatus: pending -> open

messages: + msg172675
2012-10-11 18:59:48petri.lehtinensetstatus: open -> pending
nosy: + petri.lehtinen
messages: + msg172674

2011-03-15 23:39:14schmircreate