Tue, 08/04/2020 - 11:25
Forums:
Hi,
I've compiled OpenCascade from sources successfully.
But when add #include <gp_Pnt.hxx> in my application headers, I get the following error when I try to compile my application.
OpenCascade.src\src\gp\gp_Vec2d.lxx|77|error: 'M_PI_2' was not declared in this scope; did you mean 'M_PI'?
Any suggestion would be appreciated !
Thanks,
John
Tue, 08/04/2020 - 12:41
You have not shared any information about used compiler.
Considering that you are using Visual Studio - your code might include "math.h" without _USE_MATH_DEFINES defined:
https://docs.microsoft.com/en-us/cpp/c-runtime-library/math-constants?view=vs-2019
Just including Standard_Real.hxx before your headers may help as it defines _USE_MATH_DEFINES.
Tue, 08/04/2020 - 16:06
Hi Kirill,
Thanks for your answer. I'm using GCC 9.2.0 (TDM-GCC) and target is Win64.
Your suggestion was wise since it seems the issue comes from GCC 9.2.0 itself.
It also requires the -D_USE_MATH_DEFINES option.
Now compiling like a charm... :)
Thanks!
John
Tue, 08/04/2020 - 17:07
It might be reasonable patching (contributing) an OCCT to define _USE_MATH_DEFINES also in case of gcc, not just msvc in Standard_Real.hxx.
Tue, 08/04/2020 - 16:09
A bit tricky, since M_PI (and some others) are well defined without -D_USE_MATH_DEFINES.
But M_PI_2 does requires -D_USE_MATH_DEFINES.
John
Tue, 08/04/2020 - 17:05
M_PI_2 is defined within the following #ifdef block in math.h:
> #if !defined(__STRICT_ANSI__) || defined(_XOPEN_SOURCE) || defined(_GNU_SOURCE) || defined(_BSD_SOURCE) || defined(_USE_MATH_DEFINES)
Sample program shows that M_PI_2 is available on Linux because of _GNU_SOURCE macros defined by g++ for "systems using glibc".
MinGW does not define _GNU_SOURCE, but OCCT compiles fine because of usage of "-std=gnu++0x" compiler flag instead of "-std=c++0x".
This activates GNU extensions and undefines __STRICT_ANSI__ macros.
So that as alternative you may defined C++ standard version/extensions to MinGW consistent to how OCCT was built itself.
Tue, 08/04/2020 - 18:11
Understood !
I've replaced my app previous flag c++17 by -std=gnu++0x; this indeed defines M_PI_2 without the need of -D_USE_MATH_DEFINES .
But, if you're using smart pointers with the syntax std::make_unique< , this seems conflicting with the -std=gnu++0x flag.
So, it's probably better just to add the -D_USE_MATH_DEFINES flag in your app compiler options.
John
Tue, 08/04/2020 - 18:43
-std=gnu++0x means C++0x (enabled by -std=c++0x) with GNU extensions, which was added to GCC before C++11 standard has been actually released.
This is a minimal requirement for building OCCT, but you can use a higher version if you like with -std=gnu++17 or something like this.
Tue, 08/04/2020 - 19:45
I've already tried the option -std=gnu++17.
It doesn't work ( M_PI_2 not defined) without the -D_USE_MATH_DEFINES flag.
But it's really no trouble at all to add -D_USE_MATH_DEFINES in apps compiling options.
John
Wed, 08/05/2020 - 14:48
Well, it is an unexpected behavior. g++ (tdm64-1) 5.1.0 works as expected with -std=gnu++17 flag.
Probably they have changed something in newer versions...