正常情况下配置c_cpp_properties.json文件
{
"configurations": [
{
"name": "Linux",
"includePath": [
"${workspaceFolder}/**",
"/home/sang/packages/TensorRT-8.5.1.7/include"
],
"defines": [],
"compilerPath": "/usr/bin/gcc",
"cStandard": "c17",
"cppStandard": "gnu++17",
"intelliSenseMode": "linux-gcc-x64",
"configurationProvider": "ms-vscode.cmake-tools"
}
],
"version": 4
}
配置方式修改c_cpp_properties.json文件
{
"configurations": [
{
"name": "Linux",
"includePath": [
"${workspaceFolder}/**"
],
"defines": [],
"compilerPath": "/usr/bin/gcc",
"cStandard": "c17",
"cppStandard": "gnu++17",
"intelliSenseMode": "linux-gcc-x64",
"configurationProvider": "ms-vscode.cmake-tools",
"compileCommands": "${workspaceFolder}/build/compile_commands.json"
}
],
"version": 4
}
其中"compileCommands": "${workspaceFolder}/build/compile_commands.json"为新添加文件,build/compile_commands.json为执行cmake指令后生成的文件,在build目录下。
如果build文件夹中未生成compile_commands.json文件,在CmakeLists.txt中添加
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
或者编译时带着编译指令:
cmake -S . -B build -DCMAKE_EXPORT_COMPILE_COMMANDS=ON