[fixed] new compiler warnings in Part WB

Here's the place for discussion related to coding in FreeCAD, C++ or Python. Design, interfaces and structures.
Forum rules
Be nice to others! Respect the FreeCAD code of conduct!
Post Reply
User avatar
uwestoehr
Veteran
Posts: 4961
Joined: Sun Jan 27, 2019 3:21 am
Location: Germany
Contact:

[fixed] new compiler warnings in Part WB

Post by uwestoehr »

Last week I upgraded MSVC to version 2022 but also my Windows SDK to version 10.0.19041. I see now when compiling the Part WB these new warnings:

Code: Select all

13>C:\Program Files (x86)\Windows Kits\10\Include\10.0.19041.0\ucrt\corecrt_math_defines.h(23,1): warning C4005: 'M_E': macro redefinition (compiling source file D:\FreeCADGit\src\Mod\Part\Gui\SectionCutting.cpp)
13>D:\FreeCAD-build\FreeCADLibs_2_6_x64_VC2019\include\Inventor/C/basic.h(111): message : see previous definition of 'M_E' (compiling source file D:\FreeCADGit\src\Mod\Part\Gui\SectionCutting.cpp)
13>C:\Program Files (x86)\Windows Kits\10\Include\10.0.19041.0\ucrt\corecrt_math_defines.h(24,1): warning C4005: 'M_LOG2E': macro redefinition (compiling source file D:\FreeCADGit\src\Mod\Part\Gui\SectionCutting.cpp)
13>D:\FreeCAD-build\FreeCADLibs_2_6_x64_VC2019\include\Inventor/C/basic.h(114): message : see previous definition of 'M_LOG2E' (compiling source file D:\FreeCADGit\src\Mod\Part\Gui\SectionCutting.cpp)
13>C:\Program Files (x86)\Windows Kits\10\Include\10.0.19041.0\ucrt\corecrt_math_defines.h(25,1): warning C4005: 'M_LOG10E': macro redefinition (compiling source file D:\FreeCADGit\src\Mod\Part\Gui\SectionCutting.cpp)
13>D:\FreeCAD-build\FreeCADLibs_2_6_x64_VC2019\include\Inventor/C/basic.h(117): message : see previous definition of 'M_LOG10E' (compiling source file D:\FreeCADGit\src\Mod\Part\Gui\SectionCutting.cpp)
13>C:\Program Files (x86)\Windows Kits\10\Include\10.0.19041.0\ucrt\corecrt_math_defines.h(26,1): warning C4005: 'M_LN2': macro redefinition (compiling source file D:\FreeCADGit\src\Mod\Part\Gui\SectionCutting.cpp)
13>D:\FreeCAD-build\FreeCADLibs_2_6_x64_VC2019\include\Inventor/C/basic.h(120): message : see previous definition of 'M_LN2' (compiling source file D:\FreeCADGit\src\Mod\Part\Gui\SectionCutting.cpp)
13>C:\Program Files (x86)\Windows Kits\10\Include\10.0.19041.0\ucrt\corecrt_math_defines.h(30,1): warning C4005: 'M_PI_4': macro redefinition (compiling source file D:\FreeCADGit\src\Mod\Part\Gui\SectionCutting.cpp)
13>D:\FreeCAD-build\FreeCADLibs_2_6_x64_VC2019\include\Inventor/C/basic.h(135): message : see previous definition of 'M_PI_4' (compiling source file D:\FreeCADGit\src\Mod\Part\Gui\SectionCutting.cpp)
13>C:\Program Files (x86)\Windows Kits\10\Include\10.0.19041.0\ucrt\corecrt_math_defines.h(31,1): warning C4005: 'M_1_PI': macro redefinition (compiling source file D:\FreeCADGit\src\Mod\Part\Gui\SectionCutting.cpp)
13>D:\FreeCAD-build\FreeCADLibs_2_6_x64_VC2019\include\Inventor/C/basic.h(144): message : see previous definition of 'M_1_PI' (compiling source file D:\FreeCADGit\src\Mod\Part\Gui\SectionCutting.cpp)
13>C:\Program Files (x86)\Windows Kits\10\Include\10.0.19041.0\ucrt\corecrt_math_defines.h(32,1): warning C4005: 'M_2_PI': macro redefinition (compiling source file D:\FreeCADGit\src\Mod\Part\Gui\SectionCutting.cpp)
13>D:\FreeCAD-build\FreeCADLibs_2_6_x64_VC2019\include\Inventor/C/basic.h(147): message : see previous definition of 'M_2_PI' (compiling source file D:\FreeCADGit\src\Mod\Part\Gui\SectionCutting.cpp)
13>C:\Program Files (x86)\Windows Kits\10\Include\10.0.19041.0\ucrt\corecrt_math_defines.h(35,1): warning C4005: 'M_SQRT1_2': macro redefinition (compiling source file D:\FreeCADGit\src\Mod\Part\Gui\SectionCutting.cpp)
13>D:\FreeCAD-build\FreeCADLibs_2_6_x64_VC2019\include\Inventor/C/basic.h(156): message : see previous definition of 'M_SQRT1_2' (compiling source file D:\FreeCADGit\src\Mod\Part\Gui\SectionCutting.cpp)
I am the author of SectionCutting.cpp but since I am no "real" programmer, I am a bit lost here. For example SectionCutting.cpp does not contain a definition of M_PI_4.
Can anybody help me what I have to do to get rid of the warnings?
wmayer
Founder
Posts: 20243
Joined: Thu Feb 19, 2009 10:32 am
Contact:

Re: new compiler warnings in Part WB

Post by wmayer »

You indirectly include basic.h first that defines the macros and afterwards you include cmath that redefines them. To avoid the warnings you must change the include order to include cmath first.
User avatar
uwestoehr
Veteran
Posts: 4961
Joined: Sun Jan 27, 2019 3:21 am
Location: Germany
Contact:

Re: new compiler warnings in Part WB

Post by uwestoehr »

wmayer wrote: Sun Jul 03, 2022 4:02 pm You indirectly include basic.h first that defines the macros and afterwards you include cmath that redefines them. To avoid the warnings you must change the include order to include cmath first.
I failed to do so:
- cmath is not included
- when I include <cmath> as first file. the warnings still stay

I noticed that the warnings only occur when I compile without using PCH. Maybe this is the reason why I did not see them earlier.
wmayer
Founder
Posts: 20243
Joined: Thu Feb 19, 2009 10:32 am
Contact:

Re: new compiler warnings in Part WB

Post by wmayer »

You know the compiler option to show all header files that are included when compiling a source file? Switch this option on in the properties dialog of that source file and compile it. From there you should see at what point basic.h and corecrt_math_defines.h are included.
User avatar
uwestoehr
Veteran
Posts: 4961
Joined: Sun Jan 27, 2019 3:21 am
Location: Germany
Contact:

Re: new compiler warnings in Part WB

Post by uwestoehr »

wmayer wrote: Sun Jul 03, 2022 4:59 pm You know the compiler option to show all header files that are included when compiling a source file?
No, but I googled it now.

basic.h is the first lime loaded by
# include <Inventor/actions/SoGetBoundingBoxAction.h>
The warning appears on
#include <Gui/ViewProviderGeometryObject.h>

With this info I could fix this now:
git commit 3aa4955e
wmayer
Founder
Posts: 20243
Joined: Thu Feb 19, 2009 10:32 am
Contact:

Re: [fixed] new compiler warnings in Part WB

Post by wmayer »

uwestoehr wrote: Mon Jul 04, 2022 12:15 am With this info I could fix this now:
git commit 3aa4955e
This breaks the build for all other platforms because it's a private header of msvc. Does it work to add an

Code: Select all

#undef _USE_MATH_DEFINES
?
User avatar
uwestoehr
Veteran
Posts: 4961
Joined: Sun Jan 27, 2019 3:21 am
Location: Germany
Contact:

Re: [fixed] new compiler warnings in Part WB

Post by uwestoehr »

wmayer wrote: Mon Jul 04, 2022 6:33 am This breaks the build for all other platforms because it's a private header of msvc.
I see. Meanwhile I found a solution on StackOverflow and this works for the Ci compiler and MSVC:
git commit e790566fd4
Post Reply