如何解决如何在vscode中设置“包含路径”以编译C ++
我在使用Vscode的Ubuntu 20.04。
我正在尝试编译此处的文件
我在终端上输入
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
}
和tasks.json文件
{
// 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"
},]
}
有什么想法吗?
解决方法
我怀疑问题出在编译器Args中的pkg-config。 尝试分隔每个参数:
"`pkg-config","gtkmm-3.0","--cflags","--libs`"
,
经过多次尝试 从
那里得到了解决方案c_cpp_properties.json reference
和Using C++ on Linux in VS Code
首先,我将所有文件放在同一文件夹中(在我的情况下是.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
}
和tasks.json
{
// 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","--libs`"
],"problemMatcher": [],"group": {
"kind": "build","isDefault": true
}
}
]
}
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。