C++ 如何设置";包括路径“;在vscode中编译c++;
我在Ubuntu 20.04上使用Vscode 我正试图编译这里的文件 我在终端机上打这个C++ 如何设置";包括路径“;在vscode中编译c++;,c++,ubuntu,visual-studio-code,include-path,C++,Ubuntu,Visual Studio Code,Include Path,我在Ubuntu 20.04上使用Vscode 我正试图编译这里的文件 我在终端机上打这个 g++ main.cpp examplewindow.cpp -o WindowBox11 -v -std=c++0x `pkg-config gtkmm-3.0 --cflags --libs` 它编译得很好 但不适用于Vscode 这是我的c_cpp_properties.json文件 { "configurations": [ { "name
g++ main.cpp examplewindow.cpp -o WindowBox11 -v -std=c++0x `pkg-config gtkmm-3.0 --cflags --libs`
它编译得很好
但不适用于Vscode
这是我的c_cpp_properties.json文件
{
"configurations": [
{
"name": "Linux",
"includePath": [
"${workspaceFolder}/**",
"/usr/include/gtkmm-3.0",
"/usr/include/**"
],
"defines": [],
"compilerPath": "/usr/bin/g++",
"cStandard": "gnu18",
"cppStandard": "gnu++14",
"intelliSenseMode": "gcc-x64",
"compilerArgs": [
"-std=c++0x",
"`pkg-config gtkmm-3.0 --cflags --libs`",
"-v"
]
}
],
"version": 4
{
// See https://go.microsoft.com/fwlink/?LinkId=733558
// for the documentation about the tasks.json format
"version": "2.0.0",
"tasks": [
{
"label": "build & run", //It's name of the task , you can have several tasks
"type": "shell", //type can be either 'shell' or 'process' , more details will be given below
"command": "g++",
"args": [
"-g", //gnu debugging flag , only necessary if you want to perform debugging on file
"${file}", //${file} gives full path of the file
"-o",
"${workspaceFolder}\\build\\${fileBasenameNoExtension}", //output file name
"&&", //to join building and running of the file
"${workspaceFolder}\\build\\${fileBasenameNoExtension}",
],
"group": {
"kind": "build", //defines to which group the task belongs
"isDefault": true
},
"presentation": { //Explained in detail below
"echo": false,
"reveal": "always",
"focus": true,
"panel": "shared",
"clear": false,
"showReuseMessage": false
},
"problemMatcher": "$gcc"
},
]
}
和tasks.json文件
{
"configurations": [
{
"name": "Linux",
"includePath": [
"${workspaceFolder}/**",
"/usr/include/gtkmm-3.0",
"/usr/include/**"
],
"defines": [],
"compilerPath": "/usr/bin/g++",
"cStandard": "gnu18",
"cppStandard": "gnu++14",
"intelliSenseMode": "gcc-x64",
"compilerArgs": [
"-std=c++0x",
"`pkg-config gtkmm-3.0 --cflags --libs`",
"-v"
]
}
],
"version": 4
{
// See https://go.microsoft.com/fwlink/?LinkId=733558
// for the documentation about the tasks.json format
"version": "2.0.0",
"tasks": [
{
"label": "build & run", //It's name of the task , you can have several tasks
"type": "shell", //type can be either 'shell' or 'process' , more details will be given below
"command": "g++",
"args": [
"-g", //gnu debugging flag , only necessary if you want to perform debugging on file
"${file}", //${file} gives full path of the file
"-o",
"${workspaceFolder}\\build\\${fileBasenameNoExtension}", //output file name
"&&", //to join building and running of the file
"${workspaceFolder}\\build\\${fileBasenameNoExtension}",
],
"group": {
"kind": "build", //defines to which group the task belongs
"isDefault": true
},
"presentation": { //Explained in detail below
"echo": false,
"reveal": "always",
"focus": true,
"panel": "shared",
"clear": false,
"showReuseMessage": false
},
"problemMatcher": "$gcc"
},
]
}
使用Vscode编译时,我遇到了以下错误
有什么想法吗?我怀疑问题出在compilerArgs中的pkg config上。 尝试将每个参数分开:
"`pkg-config", "gtkmm-3.0", "--cflags", "--libs`"
经过多次尝试
从中得到解决方案
及
首先,我把所有文件放在同一个文件夹中(在我的例子中是.cc和.h)
要在命令行中编译,我使用
g++ main.cc examplewindow.cc -o Dialogue_windo11 -std=c++0x `pkg-config gtkmm-3.0 --cflags --libs`
必须在vscode中复制此命令
c_cpp_properties.json
{
"env": {
"myDefaultIncludePath": ["${workspaceFolder}", "${workspaceFolder}/include"],
"myCompilerPath": "/usr/bin/g++"
},
"configurations": [
{
"name": "Linux",
"intelliSenseMode": "gcc-x64",
"includePath": ["${myDefaultIncludePath}", "/usr/include/**"],
"compilerPath": "/usr/bin",
"cStandard": "gnu18",
"cppStandard": "gnu++14",
"compilerArgs": [
"-v"
]
}
],
"version" : 4
{
// See https://go.microsoft.com/fwlink/?LinkId=733558
// for the documentation about the tasks.json format
"version": "2.0.0",
"tasks": [
{
"label": "g++ build active file",
"type": "shell",
"command": "/usr/bin/g++",
"args": [
"${fileDirname}/*.cc", //to compile all .cc files
"-o",
"${fileDirname}/MessageBox",
"-std=c++0x",
"`pkg-config", "gtkmm-3.0", "--cflags", "--libs`"
],
"problemMatcher": [],
"group": {
"kind": "build",
"isDefault": true
}
}
]
}
和tasks.json
{
"env": {
"myDefaultIncludePath": ["${workspaceFolder}", "${workspaceFolder}/include"],
"myCompilerPath": "/usr/bin/g++"
},
"configurations": [
{
"name": "Linux",
"intelliSenseMode": "gcc-x64",
"includePath": ["${myDefaultIncludePath}", "/usr/include/**"],
"compilerPath": "/usr/bin",
"cStandard": "gnu18",
"cppStandard": "gnu++14",
"compilerArgs": [
"-v"
]
}
],
"version" : 4
{
// See https://go.microsoft.com/fwlink/?LinkId=733558
// for the documentation about the tasks.json format
"version": "2.0.0",
"tasks": [
{
"label": "g++ build active file",
"type": "shell",
"command": "/usr/bin/g++",
"args": [
"${fileDirname}/*.cc", //to compile all .cc files
"-o",
"${fileDirname}/MessageBox",
"-std=c++0x",
"`pkg-config", "gtkmm-3.0", "--cflags", "--libs`"
],
"problemMatcher": [],
"group": {
"kind": "build",
"isDefault": true
}
}
]
}