c_cpp_properties.json 中的 includePath 在 C 的 VSCode 中不起作用

2024-03-02

我正在 Ubuntu 18.04 上使用 C/C++ 扩展的 VSCode 进行工作。

我试图包含 gmodule.h 并且它引发了错误gmodule.h: No such file or directory主文件第 2 行第 10 个字符。

因此,问题在于 gmodule.h 不在 /usr/include 中,而是在 /usr/include/glib-2.0 中。意识到这一点,我将此文件夹添加到 c_cpp_properties.json 中的 includePath 变量中。但是,它仍然会引发相同的错误。

使用时#include <glib-2.0/gmodule.h>代替#include <gmodule.h>,它确实有效,但这只会将问题转移到 gmodule.h 本身,因为 glib-2.0 文件夹中的其他包含内容仍然无法在 gmodule.h 内部工作。

总而言之,问题是添加到 c_cpp_properties.json 中的 includePath 不会改变任何内容,我想知道如何使其工作,因为我想使用 gmodule。

c_cpp_properties.json:

{
    "configurations": [
        {
            "name": "Linux",
            "defines": [],
            "compilerPath": "/usr/bin/gcc",
            "cStandard": "c11",
            "cppStandard": "c++17",
            "intelliSenseMode": "clang-x64",
            "includePath": [
                "/usr/include/glib-2.0/*"
            ]
        }
    ],
    "version": 4
}

现在我只是想包含 gmodule.h 并且还没有对它做任何事情,所以这是我的主文件:

#include <stdio.h>
#include <gmodule.h>

int main() {
    printf("hai\n");
    return 0;
}

The c_cpp_properties.json控制,除其他外,在哪里智能感知在 IDE 中解析包含文件。 IDE 和构建任务是独立的事物,因此在 VS Code 中独立配置和运行。

解决您的问题的方法是将包含路径添加到您的tasks.json文件,如下:

"args": [
        "-g",
        "${file}",
        "-o",
        "${fileDirname}/${fileBasenameNoExtension}",
        "--include-directory=/usr/include/glib-2.0/"
 ],
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

c_cpp_properties.json 中的 includePath 在 C 的 VSCode 中不起作用 的相关文章

随机推荐