Visual Studio 2022已设/std:c++14但__cplusplus未满足C++14编译要求
问题:VS2022已配置C14标准,但编译时仍提示需要C14支持
环境与症状
- 系统:Windows 10
- 编译器:Visual Studio 2022
- 项目配置:已设置为ISO C++14标准(
/std:c++14) - 错误信息:编译时触发bx库
platform.h第443行的#error,提示“C++14 standard support is required to build”,原因是宏判断__cplusplus < 201402L成立。
编译错误日志
Build started... 1>------ Build started: Project: my_sdl_bgfx2, Configuration: Debug x64 ------ 1>my_sdl_bgfx2.cpp 1>C:\dev\my\cpp\my_sdl_bgfx\my_sdl_bgfx2\include\bx\platform.h(443,1): fatal error C1189: #error: "C++14 standard support is required to build." 1>Done building project "my_sdl_bgfx2.vcxproj" -- FAILED. ========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========
bx库版本检查宏代码
#if defined(__cplusplus) # if __cplusplus < 201402L # error "C++14 standard support is required to build." # elif __cplusplus < 201703L # define BX_CPP_NAME "C++14" # elif __cplusplus < 201704L # define BX_CPP_NAME "C++17" # else // See: https://gist.github.com/bkaradzic/2e39896bc7d8c34e042b#orthodox-c # define BX_CPP_NAME "C++WayTooModern" # endif // BX_CPP_NAME #else # define BX_CPP_NAME "C++Unknown" #endif // defined(__cplusplus)
项目源码
#include <iostream> #include <bgfx/bgfx.h> #include <bgfx/platform.h> #include <bx/mutex.h> #include <bx/thread.h> //#include <cstdio> #include "sdl/SDL.h" #include "sdl/SDL_syswm.h" #define SDL_MAIN_HANDLED // 屏幕尺寸常量 const int SCREEN_WIDTH = 640; const int SCREEN_HEIGHT = 480; // 窗口数据 SDL_Window* mWindow; namespace { int32_t threadFunc(bx::Thread* _thread, void* _userData) { BX_UNUSED(_thread); bgfx::init(); } } int main(int argc, char** argv) { if (SDL_Init(SDL_INIT_VIDEO) < 0) { printf("SDL初始化失败。SDL错误信息:%s\n", SDL_GetError()); return 1; } mWindow = SDL_CreateWindow( "SDL教程", SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, SCREEN_WIDTH, SCREEN_HEIGHT, SDL_WINDOW_SHOWN | SDL_WINDOW_RESIZABLE | SDL_WINDOW_FULLSCREEN_DESKTOP ); if (mWindow == NULL) { printf("SDL窗口创建失败。SDL错误信息:%s\n", SDL_GetError()); return 1; } SDL_SysWMinfo wmi; SDL_VERSION(&wmi.version); if (!SDL_GetWindowWMInfo(mWindow, &wmi)) { return false; } //bgfx::PlatformData pd; SDL_SysWMinfo wmi; SDL_VERSION(&wmi.version); if (!SDL_GetWindowWMInfo(mWindow, &wmi)) { return NULL; } /*pd.nwh = wmi.info.win.window; pd.context = NULL; pd.backBuffer = NULL; pd.backBufferDS = NULL; bgfx::setPlatformData(pd); bgfx::renderFrame();*/ bool bStopMainLoop = false; while (!bStopMainLoop) { for (SDL_Event currentEvent; SDL_PollEvent(¤tEvent) != 0;) { if (currentEvent.type == SDL_QUIT) { bStopMainLoop = true; break; } } } return 0; }
VC++配置截图

解决方法
核心原因
Visual Studio为兼容旧代码,默认不会更新__cplusplus宏的数值——即使你已指定/std:c++14,该宏仍会返回旧标准的数值(如199711L),导致bx库的版本检查失败。
修复步骤
- 右键项目 → 选择「属性」
- 依次进入「配置属性」→「C/C++」→「命令行」
- 在「附加选项」输入框中添加:
/Zc:__cplusplus - 点击「确定」后重新编译项目
验证方式
在代码开头添加以下代码,编译运行后查看输出,确认__cplusplus的值为201402L:
#include <iostream> int main() { std::cout << "__cplusplus数值: " << __cplusplus << std::endl; return 0; }
补充说明
如果你的项目开启了/permissive-(严格模式),该选项会自动启用/Zc:__cplusplus,无需额外添加。
内容的提问来源于stack exchange,提问作者user63898
相关产品推荐
相关产品推荐

