Praetorian
Praetorian

Reputation: 109189

Error building Boost 1.49.0 with GCC 4.7.0

I'm trying to build Boost 1.49.0 using GCC 4.7.0 (MinGW). I keep getting the following error message several dozen times:

c:\tools\mingw\bin../lib/gcc/i686-pc-mingw32/4.7.0/../../../../include/c++/4.7.0/cmath:1096:11: error: '::hypot' has not been declared

Line 1096 of cmath contains

using ::hypot;

cmath includes math.h which declares the hypot function as

extern double __cdecl hypot (double, double); /* in libmoldname.a */

In both files, a couple of lines after the ones quoted above, are identical statements for the hypotl function (except the type is long double instead of double) and that one seems happy.

Any ideas why I am getting this error?

Upvotes: 14

Views: 6825

Answers (7)

Reza Amya
Reza Amya

Reputation: 1724

Add this line

#define _hypot hypot

at the first of your Python.h file that it is stored in your python installation directory. somewhere like C:\Python27\include.

Upvotes: 0

IanH
IanH

Reputation: 10700

The answer by @Praetorian correctly identifies the problem. On the other hand, the Python headers are technically meant to come before any others. In addition, sometimes the accepted solution does not work or is inconvenient in the build system, so I came up with an alternate solution. Add the following flag to the call to g++:

-D_hypot=hypot

This makes it so that the harmful macro in the Python headers becomes a no-op, and the compilation error goes away.

Upvotes: 17

GuTheR
GuTheR

Reputation: 81

I could solve this error in Code Blocks when I added the following path in the Linker

C:\Python36-32\libs 

and put two libs on the link libraries: libpython36.a and python36.lib.

Upvotes: 0

Shihe Zhang
Shihe Zhang

Reputation: 2771

The problem is identified correctly by @Praetorian.

In my case it only appears in one file.So I simply add

#define _hypot hypot before #include <Python.h>

and works.

Hope this can be enlightening.

Upvotes: 3

Klamer Schutte
Klamer Schutte

Reputation: 1093

As far as I can see this happens when compiling with MingW, using -std=c++0xx, and including Python.h before cmath. And note that cmath is included by quite a few other header files... Note that the problem is not Boost specific. Complicating fact is that in my standard MingW - Visual Studio cross compilation setup, Visual Studio 2010 needs in Debug mode to have Python.h included before many other standard include files. Solution is to include cmath first, followed by Python.h, so you get code like:

#include <cmath>
#include <Python.h>
#include < other standard headers >

Upvotes: 3

Praetorian
Praetorian

Reputation: 109189

Found the answer in this forum post. It seems that pyconfig.h has the following lines:

#if defined(__GNUC__) && defined(_WIN32)
// ...
#define hypot _hypot
// ...
#endif /* GNUC */

but cmath included with MinGW expects the function to be named hypot and not _hypot, which causes the compilation errors.

The fix was to include the following to my bjam command line's cxxflags option

bjam ... cxxflags="-include cmath "

This indicates that g++ should include the cmath header at the beginning of every source file.

Upvotes: 14

Igor R.
Igor R.

Reputation: 15075

Try looking at the preprocessed unit. I guess you'll find something like "#undef hypot".

Upvotes: 0

Related Questions