onnxruntime/onnxruntime/python/onnxruntime_pybind.h
Scott McKay 1aa21df149
Fix issue with debug VS2022 build when python bindings are enabled (#9794)
* Add intermediate header between the ORT code and pybind11 to workaround an issue with VS2022 debug builds by making sure corecrt.h is included first.

This avoids the _STL_ASSERT macro being defined in an incompatible way for a debug build by pybind including the python headers with _DEBUG temporarily undefined .

See #9735 for details.
2021-11-18 16:58:02 +10:00

18 lines
705 B
C

// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.
#pragma once
// If performing a debug build with VS2022 (_MSC_VER == 1930) we need to include corecrt.h before pybind
// so that the _STL_ASSERT macro is defined in a compatible way.
//
// pybind11/pybind11.h includes pybind11/detail/common.h, which undefines _DEBUG whilst including the Python headers
// (which in turn include corecrt.h). This alters how the _STL_ASSERT macro is defined and causes the build to fail.
//
// see https://github.com/microsoft/onnxruntime/issues/9735
//
#if defined(_MSC_VER) && defined(_DEBUG) && _MSC_VER >= 1930
#include <corecrt.h>
#endif
#include <pybind11/pybind11.h>