[2.2] VS2019 error C2039 in OgreFastArray.h

Discussion area about developing with Ogre-Next (2.1, 2.2 and beyond)


ExPeTe
Gnoblar
Posts: 14
Joined: Mon Feb 04, 2019 8:53 pm
x 3

[2.2] VS2019 error C2039 in OgreFastArray.h

Post by ExPeTe »

Hello,
I just started a new empty visual studio project with minimal code and only ogre for easier debugging and I`m getting the following error:

Code: Select all

1>------ Build started: Project: OgreMinimumSample, Configuration: Debug x64 ------
1>Source.cpp
1>D:\ogre-sdk-v2.2.3-vc19-x64\include\OGRE\OgreFastArray.h(83,34): error C2039: 'max': is not a member of 'std'
1>C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.26.28801\include\vector(24): message : see declaration of 'std'
1>D:\ogre-sdk-v2.2.3-vc19-x64\include\OGRE\OgreFastArray.h(370): message : see reference to class template instantiation 'Ogre::FastArray<T>' being compiled
1>Done building project "OgreMinimumSample.vcxproj" -- FAILED.
This is with the pre-build sdk, but I got the same error with ogre that I built from source recently. I thought it was a conflict with another library I´m using and quickly fixed it by adding: #include <algorithm> to OgreFastArray.h.
But now I looked at it by right clicking on "max" then "go to definition" and it leads to OgreCommon.h, which has functions called "max".
So basically VS2019 on Windows 10 gets confused and ignores the std:: .
Funnily this doesn`t happen when building ogre. It builds and installs completely fine.
I think it may have to do with the order in which headers are included by the user.

To reproduce just add the following headers to a source file in an empty project and tell VS2019 where the headers and libs are located.

Code: Select all

#include "OgreWindowEventUtilities.h"
#include "Vao/OgreVaoManager.h"
#include "OgreRoot.h"
#include "OgreRenderSystem.h"
#include "OgreWindow.h"
#include "OgreCamera.h"
#include "Compositor/OgreCompositorManager2.h"
No other code needed. It doesn`t build further than that.
User avatar
dark_sylinc
OGRE Team Member
OGRE Team Member
Posts: 5446
Joined: Sat Jul 21, 2007 4:55 pm
Location: Buenos Aires, Argentina
x 1348

Re: [2.2] VS2019 error C2039 in OgreFastArray.h

Post by dark_sylinc »

#define NOMINMAX as early as possible in your cpp file.
Windows' macros are interfering.
ExPeTe
Gnoblar
Posts: 14
Joined: Mon Feb 04, 2019 8:53 pm
x 3

Re: [2.2] VS2019 error C2039 in OgreFastArray.h

Post by ExPeTe »

#define NOMINMAX as early as possible in your cpp file.
Windows' macros are interfering.
Changing the code to:

Code: Select all

#define NOMINMAX

#include "OgreWindowEventUtilities.h"
#include "Vao/OgreVaoManager.h"
#include "OgreRoot.h"
#include "OgreRenderSystem.h"
#include "OgreWindow.h"
#include "OgreCamera.h"
#include "Compositor/OgreCompositorManager2.h"
doesn`t do anything, the error stays the same.

It doesn`t even need multiple Ogre headers to trigger the error, just one is enough.
ExPeTe
Gnoblar
Posts: 14
Joined: Mon Feb 04, 2019 8:53 pm
x 3

Re: [2.2] VS2019 error C2039 in OgreFastArray.h

Post by ExPeTe »

I found the reason for the error:
In OgreStdHeaders.h "OgreFastArray.h" is included before " <algorithm>".
Changing the position to anywhere after algorithm fixes the error.

The reason why building ogre works is probably, that <algorithm> is included somwhere else, before ogre files that use OgreFastArray are included.
I`m saying that because when I include <algorithm> in my source file before the ogre headers I also don`t get the error.

The reason why it worked in 2.1 is that "#include <queue>" was included before "#include "OgreFastArray.h"". And <queue> itself includes <algorithm>.
"#include <queue>" was removed in 2.2.