# VC++ 2022 (C++17) Compile Errors

**URL:** <https://forum.opencv.org/t/vc-2022-c-17-compile-errors/16229>\
**Category:** C++\
**Tags:** build\
**Created:** [January 21, 2024, 8:49pm UTC](https://forum.opencv.org/t/vc-2022-c-17-compile-errors/16229 "2024-01-21T20:49:09Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![JayJayEl](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.opencv.org/jayjayel/32/9293_2.png) [@JayJayEl](https://forum.opencv.org/u/JayJayEl)\
**Post date:** [January 21, 2024, 8:49pm UTC](https://forum.opencv.org/t/vc-2022-c-17-compile-errors/16229/1 "2024-01-21T20:49:09Z")

</div>

I’m getting the following errors when compiling a C++ app in Visual Studio 2022 (C++ 17 standard). Note that this is just a small excerpt; many other related or similar errors follow.

```auto
1>------ Build started: Project: Jeweligami.BackOffice, Configuration: Debug x64 ------
1>ImageProcessor.cpp
1>F:\$oftware\Framework\OpenSource\OpenCV\build\include\opencv2\core\cvstd.hpp(135,51): error C2760: syntax error: 'static_cast' was unexpected here; expected 'type specifier'
1>(compiling source file '/ImageProcessor.cpp')
1>F:\$oftware\Framework\OpenSource\OpenCV\build\include\opencv2\core\cvstd.hpp(135,51):
1>the template instantiation context (the oldest one first) is
1>	F:\$oftware\Framework\OpenSource\OpenCV\build\include\opencv2\core\cvstd.hpp(139,2):
1>	see reference to class template instantiation 'cv::Allocator<_Tp>' being compiled
1>F:\$oftware\Framework\OpenSource\OpenCV\build\include\opencv2\core\cvstd.hpp(135,51): error C2760: syntax error: 'static_cast' was unexpected here; expected ')'

```

Here’s a snippet of cvstd.hpp (in OpenCV\build\include\opencv2\core), around the area where the error was flagged (line 135, char 51):

 ![image](https://us1.discourse-cdn.com/flex020/uploads/opencv/original/2X/c/cb03eeefa9368a0507c80258d58961dc32a1aea1.png)

Also, I’m not building static libraries, but rather, I’m trying to use the pre-built DLLs - I’ve done the minimal installation required, i.e. configuring OpenCV\_DIR environment setting, as well as specifying the OpenCV\build\include in my INCLUDE path.

I’ve never encountered this error in VC++ before; wondering if anyone would know what setting(s) I need to set/unset in order to resolve it. Unfortunately, I can’t drop to a lower standard (like 11) if that’s what’s needed - although the lowest standard available in my platform is 14, the app actually requires at least 17.

Regards,  
-JL

---

<div class="post-metadata">

**Author:** ![Ragster](https://avatars.discourse-cdn.com/v4/letter/r/6bbea6/32.png) [@Ragster](https://forum.opencv.org/u/Ragster)\
**Post date:** [February 12, 2026, 11:27am UTC](https://forum.opencv.org/t/vc-2022-c-17-compile-errors/16229/2 "2026-02-12T11:27:32Z")

</div>

Hopefully you managed to find a solution to this issue, but I thought I’d post in case anyone else has the issue and this solution works for them.

We just came across what looks like exactly the same problem - what was compiling fine in VS2019 with a debug build failed with the same error message in VS2022.

We tracked the problem down to the use of the DEBUG\_NEW macro replacement which we have on for tracing memory leaks in debug builds, using the classic

#ifdef \_DEBUG  
#define DBG\_NEW new ( \_NORMAL\_BLOCK , \ __FILE_\_ , \__ LINE_\_ )  
#else  
#define DBG\_NEW new  
#endif

If this definition is used before including the OpenCV headers, the VS2022 compiler doesn’t like it. (Intel 2023 compiler has no issues with it.)  
Solutions are either remove that definition, or ensure that the definition is created after the inclusion of OpenCV headers.

HTH
