使用“-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)
main.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:“......是否有可能从通过CMake创建的项目中继承CppProperties包含?如果是这样,从Windows CMake项目获取Linux intellisense将是轻而易举的并且将解决Linux的一个主要问题(需要指定所有包括手动项目。“ Will Buik [MSFT]:“今天不支持。......”
我已经尝试过,并且没有运气使用与"Open Folder projects in Visual C++" documentation推荐的相似的东西。
Project / Edit Settings / CppProperties.json
...
"compilerSwitches": "/std:c++17",
"intelliSenseMode": "windows-msvc-x86"
...
或任何其他支持的模式:
参考
要为C ++启用正确的Intellisense 17,请在项目定义之前在CMakeLists.txt中指定set(CMAKE_CXX_STANDARD 17)
;不需要其他配置。 CMake将在构建时为clang-cl提供-std=c++17
。
cmake_minimum_required (VERSION 3.9.2)
set(CMAKE_CXX_STANDARD 17)
project ("test")
add_executable (Test "test.cpp" "test.h")
在Visual Studio 2017 15.9.8中验证