如何为GTK3配置VSCode以进行智能感知/构建/调试和G ++ [英] How to configure VSCode for GTK3 for intellisense / build / debug and g++
问题描述
我正在使用
- g ++
- GTK3
- VSCode
如何使以下各项起作用:
How do I get the following to work:
- gtk的智能/代码完成
- 内置于VSCode中
- 使用VSCode进行调试
问题:
VSCode找不到包含项-特别是 #include< gtk/gtk.h>
在源代码中为红色.
VSCode does not find includes - especially #include <gtk/gtk.h>
is red in source.
推荐答案
要注意的重要一点是,您需要告诉VSCode包含路径和编译器标志才能正常工作.
The important thing to note is, that you need to tell VSCode the include paths and compiler flags to work properly.
- 第一步:在VSCode中打开目标文件夹.
- 现在,您应该在其中有一个新的隐藏文件夹
.vscode
.打开它. - 您要将
pkg-config --cflags gtk + -3.0
和pkg-config --libs gtk + -3.0
的输出应用于它们各自的配置. li>
- First step: Open the target folder in VSCode.
- Now you should have a new hidden folder
.vscode
in there. Open it. - You want to apply the output of
pkg-config --cflags gtk+-3.0
andpkg-config --libs gtk+-3.0
to their respective configs.
- 创建文件
.vscode/c_cpp_properties.json
. -
添加以下内容.
- Create a file
.vscode/c_cpp_properties.json
. Add the following content.
{
"env": {
"myDefaultIncludePath": [
"${workspaceFolder}",
"${workspaceFolder}/include"
],
"myCompilerPath": "/usr/local/bin/g++"
},
"configurations": [
{
"name": "include paths",
"intelliSenseMode": "g++-8",
"includePath": [
"/usr/include/gtk-3.0",
"/usr/include/at-spi2-atk/2.0",
"/usr/include/at-spi-2.0",
"/usr/include/dbus-1.0",
"/usr/lib/x86_64-linux-gnu/dbus-1.0/include",
"/usr/include/gtk-3.0",
"/usr/include/gio-unix-2.0",
"/usr/include/cairo",
"/usr/include/libdrm",
"/usr/include/pango-1.0",
"/usr/include/harfbuzz",
"/usr/include/pango-1.0",
"/usr/include/fribidi",
"/usr/include/atk-1.0",
"/usr/include/cairo",
"/usr/include/pixman-1",
"/usr/include/freetype2",
"/usr/include/libpng16",
"/usr/include/gdk-pixbuf-2.0",
"/usr/include/libmount",
"/usr/include/blkid",
"/usr/include/uuid",
"/usr/include/glib-2.0",
"/usr/lib/x86_64-linux-gnu/glib-2.0/include"
],
"compilerPath": "/usr/local/bin/g++",
"cStandard": "c11",
"cppStandard": "c++17",
"browse": {
"path": [
"${workspaceFolder}"
],
"limitSymbolsToIncludedHeaders": true,
"databaseFilename": ""
}
}
],
"version": 4
}
请注意,"includePath"的内容是 pkg-config --cflags gtk + -3.0
的输出,不带 -I
且带有双引号和逗号.您可能必须根据计算机的输出来调整值
Note, that the content of "includePath" is the output of pkg-config --cflags gtk+-3.0
without the preceeding -I
s and with double quotes and commas. You may have to adjust the values according the output of your machine
您要在 .vscode/tasks.json
中创建一个具有以下内容的新任务:
You want to create a new task inside .vscode/tasks.json
with the following content:
{
"type": "shell",
"label": "gcc debug build active file - with GTK",
"command": "/usr/bin/gcc",
"args": [
"-g",
"-pthread",
"-I/usr/include/gtk-3.0",
"-I/usr/include/at-spi2-atk/2.0",
"-I/usr/include/at-spi-2.0",
"-I/usr/include/dbus-1.0",
"-I/usr/lib/x86_64-linux-gnu/dbus-1.0/include",
"-I/usr/include/gtk-3.0",
"-I/usr/include/gio-unix-2.0",
"-I/usr/include/cairo",
"-I/usr/include/libdrm",
"-I/usr/include/pango-1.0",
"-I/usr/include/harfbuzz",
"-I/usr/include/pango-1.0",
"-I/usr/include/fribidi",
"-I/usr/include/atk-1.0",
"-I/usr/include/cairo",
"-I/usr/include/pixman-1",
"-I/usr/include/freetype2",
"-I/usr/include/libpng16",
"-I/usr/include/gdk-pixbuf-2.0",
"-I/usr/include/libmount",
"-I/usr/include/blkid",
"-I/usr/include/uuid",
"-I/usr/include/glib-2.0",
"-I/usr/lib/x86_64-linux-gnu/glib-2.0/include",
"${file}",
"-lgtk-3",
"-lgdk-3",
"-lpangocairo-1.0",
"-lpango-1.0",
"-latk-1.0",
"-lcairo-gobject",
"-lcairo",
"-lgdk_pixbuf-2.0",
"-lgio-2.0",
"-lgobject-2.0",
"-lglib-2.0",
"-o",
"${fileDirname}/${fileBasenameNoExtension}"
],
"options": {
"cwd": "/usr/bin"
},
"problemMatcher": [
"$gcc"
],
"group": {
"kind": "build",
"isDefault": true
}
}
- 请注意
args
中另外两个缩进部分. - 最上面的还是
pkg-config --cflags gtk + -3.0
的输出.(不过这次是-I
s.) - 底部是
pkg-config --libs gtk + -3.0
的输出(引号和逗号) - 您可能还需要根据计算机上命令的实际输出来调整这些值
- Note the two more indented parts within
args
. - The top one is again the output of
pkg-config --cflags gtk+-3.0
. (This time with the-I
s, though.) - The bottom part is the output of
pkg-config --libs gtk+-3.0
(quoted and commated) - You might need to adjust these values as well, according to the actual output of the commands on your machine
您要在 .vscode/launch.json
文件中创建新的配置.在我的设置中,vscode一直使用错误的配置,因此我删除了其他配置.以下是该文件的全部内容,只有一种配置.
You want to create a new configuration inside the .vscode/launch.json
file. On my setup vscode kept using the wrong configuration, so I deleted the others. Below is the full content of the file with only one configuration.
{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"name": "debug with gdb (no build)",
"type": "cppdbg",
"request": "launch",
"program": "${fileDirname}/${fileBasenameNoExtension}",
"args": [],
"stopAtEntry": false,
"cwd": "${workspaceFolder}",
"environment": [],
"externalConsole": false,
"MIMode": "gdb",
"setupCommands": [
{
"description": "Enable pretty-printing for gdb",
"text": "-enable-pretty-printing",
"ignoreFailures": true
}
],
"preLaunchTask": "",
"miDebuggerPath": "/usr/bin/gdb"
}
]
}
这篇关于如何为GTK3配置VSCode以进行智能感知/构建/调试和G ++的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!