gpt4 book ai didi

c++ - 启用 c++17 intellisense 打开文件夹 visual studio ninja-clang

转载 作者:太空狗 更新时间:2023-10-29 21:34:09 24 4
gpt4 key购买 nike

使用“-Xclang -std=c++17”我可以构建可执行文件,但是我找不到激活 c++17 intellisense 的内容。我已经尝试了很多组合,如下所示,但似乎都不起作用

CMakeLists.txt

cmake_minimum_required(VERSION 3.9.2)
set(CMAKE_CXX_STANDARD 17)
project(myapp)
add_compile_options("-Xclang" "-std=c++17")
add_executable(myapp main.cpp)
set_target_properties(myapp PROPERTIES CXX_STANDARD 17)
target_compile_features(myapp PRIVATE cxx_std_17)

主要.cpp

#include <tuple>
namespace test1::test2 // red [qualified name is not allowed]
// ^^^^^^^^^^^^^
{}

int main()
{
auto[a, b] = std::pair<int, int>();
// ^^^^^^
return 0;
}

CMakeSettings.json

{
// See https://go.microsoft.com//fwlink//?linkid=834763 for more information about this file.
"configurations": [
{
"name": "x64-Debug",
"generator": "Ninja",
"configurationType": "Debug",
"inheritEnvironments": [ "msvc_x64_x64" ],
"buildRoot": "${env.USERPROFILE}\\CMakeBuilds\\${workspaceHash}\\build\\${name}",
"installRoot": "${env.USERPROFILE}\\CMakeBuilds\\${workspaceHash}\\install\\${name}",
"cmakeCommandArgs": "",
"buildCommandArgs": "-v",
"ctestCommandArgs": "",
"variables": [
{
"name": "CMAKE_CXX_COMPILER",
"value": "clang-cl"
},
{
"name": "CMAKE_C_COMPILER",
"value": "clang-cl"
},
{
"name": "CMAKE_SYSTEM_NAME",
"value": "Windows"
}
]
}
]
}

最佳答案

至于 2017 年 12 月,定义 IntelliSense 模式的唯一方法是通过根文件夹中的 CppProperties.json 文件,您不能将其与 CMakeSettings.json.

请参阅 Visual C++ Team Blog: Customizing your Environment with Visual C++ and Open Folder 下的评论:

  • justanotherdev: "... Would it be possible to inherit CppProperties includes from the project created via CMake? If so, getting Linux intellisense from the Windows CMake project would be a breeze and would solve a major issue with Linux (needing to specify all the includes for a project manually)."
    • Will Buik [MSFT]: "This isn’t supported today. ..."

我已经尝试过了,但没有成功使用类似于 "Open Folder projects in Visual C++" documentation 中推荐的东西.

  1. 我确实去了 Project/Edit Settings/CppProperties.json

    enter image description here

  2. 并插入到我的配置中进行测试,例如

    ...
    "compilerSwitches": "/std:c++17",
    "intelliSenseMode": "windows-msvc-x86"
    ...

    或任何其他支持的模式:

    enter image description here


引用资料

关于c++ - 启用 c++17 intellisense 打开文件夹 visual studio ninja-clang,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47855545/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com