[英]Correct settings for C++ to recognize compiler options?
在 VS Code 中,我有一個未找到的定義標識符。 該變量最終作為標志-DENABLE_LOGS_PREVIEW
傳遞給編譯器,並在./cmake-build-debug/build.ninja
中找到。 我直接從命令行使用 CMake 和 Ninja 構建。
#ifdef ENABLE_LOGS_PREVIEW
std::cout << "Hello world" << std::endl;
#endif
std::cout << "Goodbye world" << std::endl;
正確打印,盡管 VS Code 將std::cout << "Hello world" << std::endl;
變灰
Hello world
Goodbye world
我正在努力獲得正確的c_cpp_properties.json
來處理我的工作流程。 如何讓上述定義得到認可?
這里的答案是讓 CMake 生成一個compile_commands.json並將其添加到 VS Code c_cpp_properties.json
,如下所示:
"compileCommands": "${workspaceFolder}/cmake-build-debug/compile_commands.json"
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.