无法在 Studio Code 中打开源文件“glibconfig.h”(“gtk/gtk.h”的依赖项)

5 c gtk gcc visual-studio-code

我已经在 Visual Studio Code 中配置了任务 json

{
    "tasks": [
        {
            "type": "shell",
            "label": "gcc build active file",
            "command": "/usr/lib64/ccache/gcc",
            "args": [
                "-g",
                "${file}",
                "-o",
                "${fileDirname}/${fileBasenameNoExtension}",
                "`pkg-config", "--cflags", "--libs","gtk+-3.0`"
            ],
            "options": {
                "cwd": "/usr/lib64/ccache"
            },
            "problemMatcher": [],
            "group": {
                "kind": "build",
                "isDefault": true
            }
        }
    ],
    "version": "2.0.0"
}
Run Code Online (Sandbox Code Playgroud)

我认为终端输出没问题,构建没有问题:

> Executing task: /usr/lib64/ccache/gcc -g /home/giuliohome/dev/gnome/gtk-example/gtk_hello02.c -o /home/giuliohome/dev/gnome/gtk-example/gtk_hello02 `pkg-config --cflags --libs gtk+-3.0` <
Run Code Online (Sandbox Code Playgroud)

出于一个奇怪的原因,我不太明白,Visual Studio Code 编辑器需要不同的、单独的配置,.vscode/c_cpp_properties.json并且它仍然抱怨#include <gtk/gtk.h>

问题消息说明:

无法打开源文件“ glibconfig.h”(“ gtk/gtk.h”的依赖项)

我已经尝试做的是通过目视检查我的/usr/inlcude结构添加 3 个目录

但是(因为它包含很多文件和子文件夹)我对这种继续进行的方式感到困惑(我应该继续搜索所有这些嵌套的包含依赖项吗?)无论如何我不知道接下来要添加什么.. 。

{
    "configurations": [
        {
            "name": "Linux",
            "includePath": [
                "${workspaceFolder}/**",
                "/usr/include/linux",
                "/usr/include/gtk-3.0",
                "/usr/include/glib-2.0"
            ],
            "defines": [],
            "compilerPath": "/usr/lib64/ccache/gcc",
            "cStandard": "c11",
            "cppStandard": "gnu++14",
            "intelliSenseMode": "clang-x64"
        }
    ],
    "version": 4
}
Run Code Online (Sandbox Code Playgroud)

Ian*_*cer 11

通过将以下内容添加到以下内容,我能够消除错误includePath

        "includePath": [
            "${workspaceFolder}/**",
            "/usr/include/glib-2.0",
            "/usr/lib/x86_64-linux-gnu/glib-2.0/include"
        ],
Run Code Online (Sandbox Code Playgroud)


小智 2

两年后,这仍然是Studio Code 的一个开放问题

很明显,它是不可管理的,无论如何,为了您的信息,这是我的 Fedora 31 Linux 工作站上的解决方案:

{
    "configurations": [
        {
            "name": "Linux",
            "includePath": [
                "${workspaceFolder}/**",
                "/usr/include/linux",
                "/usr/include/gtk-3.0",
                "/usr/include/glib-2.0",
                "/usr/lib64/glib-2.0/include",
                "/usr/include/pango-1.0",
                "/usr/include/harfbuzz",
                "/usr/include/cairo",
                "/usr/include/gdk-pixbuf-2.0",
                "/usr/include/atk-1.0"
            ],
            "defines": [],
            "compilerPath": "/usr/lib64/ccache/gcc",
            "cStandard": "c11",
            "cppStandard": "gnu++14",
            "intelliSenseMode": "clang-x64"
        }
    ],
    "version": 4
}
Run Code Online (Sandbox Code Playgroud)