就在十小时前,我想在我的 Arch-Linux 笔记本电脑上试用 GTK 并找到了 GTK-introduction-Page。
我将代码 1:1 复制到 VSCode 中的三个文件中。天真地尝试构建它,向我展示了这需要进一步设置。所以我添加了 .vscode 文件夹和两个必要的 JSON 文件。虽然 IntelliSense 现在对代码很好,但 GCC 仍然会抛出错误,未找到 #include <gtkmm/button.h>
- 同时我可以右键单击标题并以这种方式打开它。我把库放在 pkg-config --cflags --libs gtkmm-3.0
得到的参数上。我希望,有些人知道我错过了什么。我在使用 clang 和 gcc 时遇到了这些问题。
c_cpp_properties.json
"env": {
"myDefaultIncludePath": [
"${workspaceFolder}",
"${workspaceFolder}/include"
],
"myCompilerPath": "/usr/local/bin/g++"
},
"configurations": [
{
"name": "include paths",
"intelliSenseMode": "gcc-x64"
,
"includePath": [
"/usr/include/gtk-3.0",
"/usr/include/pango-1.0",
"/usr/include/glib-2.0",
"/usr/lib/glib-2.0/include",
"/usr/include/harfbuzz",
"/usr/include/freetype2",
"/usr/include/libpng16",
"/usr/include/libmount",
"/usr/include/blkid",
"/usr/include/fribidi",
"/usr/include/cairo",
"/usr/include/lzo",
"/usr/include/pixman-1",
"/usr/include/gdk-pixbuf-2.0",
"/usr/include/gio-unix-2.0",
"/usr/include/cloudproviders",
"/usr/include/atk-1.0",
"/usr/include/at-spi2-atk/2.0",
"/usr/include/dbus-1.0",
"/usr/lib/dbus-1.0/include",
"/usr/include/at-spi-2.0",
"/usr/include/gtkmm-3.0",
"/usr/lib/gtkmm-3.0/include",
"/usr/include/giomm-2.4",
"/usr/lib/giomm-2.4/include",
"/usr/include/glib-2.0",
"/usr/lib/glib-2.0/include",
"/usr/include/libmount",
"/usr/include/blkid",
"/usr/include/glibmm-2.4",
"/usr/lib/glibmm-2.4/include",
"/usr/include/sigc++-2.0",
"/usr/lib/sigc++-2.0/include",
"/usr/include/gtk-3.0",
"/usr/include/pango-1.0",
"/usr/include/harfbuzz",
"/usr/include/freetype2",
"/usr/include/libpng16",
"/usr/include/fribidi",
"/usr/include/cairo",
"/usr/include/lzo",
"/usr/include/pixman-1",
"/usr/include/gdk-pixbuf-2.0",
"/usr/include/gio-unix-2.0",
"/usr/include/cloudproviders",
"/usr/include/atk-1.0",
"/usr/include/at-spi2-atk/2.0",
"/usr/include/dbus-1.0",
"/usr/lib/dbus-1.0/include",
"/usr/include/at-spi-2.0",
"/usr/include/cairomm-1.0",
"/usr/lib/cairomm-1.0/include",
"/usr/include/pangomm-1.4",
"/usr/lib/pangomm-1.4/include",
"/usr/include/atkmm-1.6",
"/usr/lib/atkmm-1.6/include",
"/usr/include/gtk-3.0/unix-print",
"/usr/include/gdkmm-3.0",
"/usr/lib/gdkmm-3.0/include"
],
"compilerPath": "/usr/bin/gcc",
"cStandard": "c11",
"cppStandard": "c++17",
"browse": {
"path": [
"${workspaceFolder}"
],
"limitSymbolsToIncludedHeaders": true,
"databaseFilename": ""
}
}
],
"version": 4
}
tasks.json
{
"version": "2.0.0",
"tasks": [
{
"type": "shell",
"label": "gcc debug build active file - with GTK",
"command": "/usr/bin/gcc",
"args": [
"-g",
"-pthread",
"/usr/include/gtkmm-3.0",
"/usr/lib/gtkmm-3.0/include",
"/usr/include/giomm-2.4",
"/usr/lib/giomm-2.4/include",
"/usr/include/glib-2.0",
"/usr/lib/glib-2.0/include",
"/usr/include/libmount",
"/usr/include/blkid",
"/usr/include/glibmm-2.4",
"/usr/lib/glibmm-2.4/include",
"/usr/include/sigc++-2.0",
"/usr/lib/sigc++-2.0/include",
"/usr/include/gtk-3.0",
"/usr/include/pango-1.0",
"/usr/include/harfbuzz",
"/usr/include/freetype2",
"/usr/include/libpng16",
"/usr/include/fribidi",
"/usr/include/cairo",
"/usr/include/lzo",
"/usr/include/pixman-1",
"/usr/include/gdk-pixbuf-2.0",
"/usr/include/gio-unix-2.0",
"/usr/include/cloudproviders",
"/usr/include/atk-1.0",
"/usr/include/at-spi2-atk/2.0",
"/usr/include/dbus-1.0",
"/usr/lib/dbus-1.0/include",
"/usr/include/at-spi-2.0",
"/usr/include/cairomm-1.0",
"/usr/lib/cairomm-1.0/include",
"/usr/include/pangomm-1.4",
"/usr/lib/pangomm-1.4/include",
"/usr/include/atkmm-1.6",
"/usr/lib/atkmm-1.6/include",
"/usr/include/gtk-3.0/unix-print",
"/usr/include/gdkmm-3.0",
"/usr/lib/gdkmm-3.0/include",
"${file}",
"-lgtkmm-3.0",
"-latkmm-1.6",
"-lgdkmm-3.0",
"-lgiomm-2.4",
"-lgtk-3",
"-lgdk-3",
"-lz",
"-latk-1.0",
"-lcairo-gobject",
"-lgio-2.0",
"-lpangomm-1.4",
"-lglibmm-2.4",
"-lcairomm-1.0",
"-lsigc-2.0",
"-lpangocairo-1.0",
"-lpango-1.0",
"-lharfbuzz",
"-lcairo",
"-lgdk_pixbuf-2.0",
"-lgobject-2.0",
"-lglib-2.0",
"-o",
"${fileDirname}/${fileBasenameNoExtension}"
],
"options": {
"cwd": "/usr/bin"
},
"problemMatcher": [
"$gcc"
],
"group": {
"kind": "build",
"isDefault": true
}
}
]
}
此设置深受 this Stack-Overflow 的启发。
编译器输出:
> Executing task: /usr/bin/gcc -g -pthread /usr/include/gtkmm-3.0 /usr/lib/gtkmm-3.0/include /usr/include/giomm-2.4
/usr/lib/giomm-2.4/include /usr/include/glib-2.0 /usr/lib/glib-2.0/include /usr/include/libmount /usr/include/blkid /usr/include/glibmm-2.4 /usr/lib/glibmm-2.4/include /usr/include/sigc++-2.0 /usr/lib/sigc++-2.0/include /usr/include/gtk-3.0 /usr/include/pango-1.0 /usr/include/harfbuzz /usr/include/freetype2 /usr/include/libpng16 /usr/include/fribidi /usr/include/cairo /usr/include/lzo /usr/include/pixman-1 /usr/include/gdk-pixbuf-2.0 /usr/include/gio-unix-2.0 /usr/include/cloudproviders /usr/include/atk-1.0 /usr/include/at-spi2-atk/2.0 /usr/include/dbus-1.0 /usr/lib/dbus-1.0/include /usr/include/at-spi-2.0 /usr/include/cairomm-1.0 /usr/lib/cairomm-1.0/include /usr/include/pangomm-1.4 /usr/lib/pangomm-1.4/include /usr/include/atkmm-1.6 /usr/lib/atkmm-1.6/include /usr/include/gtk-3.0/unix-print /usr/include/gdkmm-3.0 /usr/lib/gdkmm-3.0/include /home/bernhard/Projekte/hellogtk/helloworld.h -lgtkmm-3.0 -latkmm-1.6 -lgdkmm-3.0 -lgiomm-2.4 -lgtk-3 -lgdk-3 -lz -latk-1.0 -lcairo-gobject -lgio-2.0 -lpangomm-1.4 -lglibmm-2.4 -lcairomm-1.0 -lsigc-2.0 -lpangocairo-1.0 -lpango-1.0 -lharfbuzz -lcairo -lgdk_pixbuf-2.0 -lgobject-2.0 -lglib-2.0 -o /home/bernhard/Projekte/hellogtk/helloworld <
/home/bernhard/Projekte/hellogtk/helloworld.h:5:10: schwerwiegender Fehler: gtkmm/window.h: Datei oder Verzeichnis nicht gefunden
5 | #include <gtkmm/window.h>
| ^~~~~~~~~~~~~~~~
Kompilierung beendet.
Der Terminalprozess "/bin/bash '-c', '/usr/bin/gcc -g -pthread /usr/include/gtkmm-3.0 /usr/lib/gtkmm-3.0/include /usr/include/giomm-2.4 /usr/lib/giomm-2.4/include /usr/include/glib-2.0 /usr/lib/glib-2.0/include /usr/include/libmount /usr/include/blkid /usr/include/glibmm-2.4 /usr/lib/glibmm-2.4/include /usr/include/sigc++-2.0 /usr/lib/sigc++-2.0/include /usr/include/gtk-3.0 /usr/include/pango-1.0 /usr/include/harfbuzz /usr/include/freetype2 /usr/include/libpng16 /usr/include/fribidi /usr/include/cairo /usr/include/lzo /usr/include/pixman-1 /usr/include/gdk-pixbuf-2.0 /usr/include/gio-unix-2.0 /usr/include/cloudproviders /usr/include/atk-1.0 /usr/include/at-spi2-atk/2.0 /usr/include/dbus-1.0 /usr/lib/dbus-1.0/include /usr/include/at-spi-2.0 /usr/include/cairomm-1.0 /usr/lib/cairomm-1.0/include /usr/include/pangomm-1.4 /usr/lib/pangomm-1.4/include /usr/include/atkmm-1.6 /usr/lib/atkmm-1.6/include /usr/include/gtk-3.0/unix-print /usr/include/gdkmm-3.0 /usr/lib/gdkmm-3.0/include /home/bernhard/Projekte/hellogtk/helloworld.h -lgtkmm-3.0 -latkmm-1.6 -lgdkmm-3.0 -lgiomm-2.4 -lgtk-3 -lgdk-3 -lz -latk-1.0 -lcairo-gobject -lgio-2.0 -lpangomm-1.4 -lglibmm-2.4 -lcairomm-1.0 -lsigc-2.0 -lpangocairo-1.0 -lpango-1.0 -lharfbuzz -lcairo -lgdk_pixbuf-2.0 -lgobject-2.0 -lglib-2.0 -o /home/bernhard/Projekte/hellogtk/helloworld'" konnte nicht gestartet werden (Exitcode: 1).
答案 0 :(得分:0)
在重新检查我的设置后,我识别出了 tasks.json 中的 Missing -I。此外,我还必须将这两个文件添加到 Args 中:
"args": [
"-g",
"-I${workspaceFolder}",
"-pthread",
"-I/usr/include/gtkmm-3.0",
"-I/usr/lib/gtkmm-3.0/include",
"-I/usr/include/giomm-2.4",
"-I/usr/lib/giomm-2.4/include",
"-I/usr/include/glib-2.0",
"-I/usr/lib/glib-2.0/include",
"-I/usr/include/libmount",
"-I/usr/include/blkid",
"-I/usr/include/glibmm-2.4",
"-I/usr/lib/glibmm-2.4/include",
"-I/usr/include/sigc++-2.0",
"-I/usr/lib/sigc++-2.0/include",
"-I/usr/include/gtk-3.0",
"-I/usr/include/pango-1.0",
"-I/usr/include/harfbuzz",
"-I/usr/include/freetype2",
"-I/usr/include/libpng16",
"-I/usr/include/fribidi",
"-I/usr/include/cairo",
"-I/usr/include/lzo",
"-I/usr/include/pixman-1",
"-I/usr/include/gdk-pixbuf-2.0",
"-I/usr/include/gio-unix-2.0",
"-I/usr/include/cloudproviders",
"-I/usr/include/atk-1.0",
"-I/usr/include/at-spi2-atk/2.0",
"-I/usr/include/dbus-1.0",
"-I/usr/lib/dbus-1.0/include",
"-I/usr/include/at-spi-2.0",
"-I/usr/include/cairomm-1.0",
"-I/usr/lib/cairomm-1.0/include",
"-I/usr/include/pangomm-1.4",
"-I/usr/lib/pangomm-1.4/include",
"-I/usr/include/atkmm-1.6",
"-I/usr/lib/atkmm-1.6/include",
"-I/usr/include/gtk-3.0/unix-print",
"-I/usr/include/gdkmm-3.0",
"-I/usr/lib/gdkmm-3.0/include",
"/home/bernhard/Projekte/hellogtk/main.cpp",
"/home/bernhard/Projekte/hellogtk/helloworld.cpp",
"-lgtkmm-3.0",
"-latkmm-1.6",
"-lgdkmm-3.0",
"-lgiomm-2.4",
"-lgtk-3",
"-lgdk-3",
"-lz",
"-latk-1.0",
"-lcairo-gobject",
"-lgio-2.0",
"-lpangomm-1.4",
"-lglibmm-2.4",
"-lcairomm-1.0",
"-lsigc-2.0",
"-lpangocairo-1.0",
"-lpango-1.0",
"-lharfbuzz",
"-lcairo",
"-lgdk_pixbuf-2.0",
"-lgobject-2.0",
"-lglib-2.0",
"-Wpedantic",
"-o",
"${fileDirname}/${fileBasenameNoExtension}"
],
我也不得不从 "command": "/usr/bin/gcc"
切换到 "command": "/usr/bin/g++"
,因为这会以正确的方式链接和解释 C++ 代码。
现在它似乎工作得很好。当然,我更喜欢,如果编译器/链接器会自动检测所有 .cpp 文件。不过现在还好。