我正在Ubuntu 18.04上使用VSCode和C/C++扩展。
我试图包含gmodule.h,但它在主文件的第2行第10个字符处引发了错误gmodule.h: No such file or directory
。
因此,问题在于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_属性.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;
}
4条答案
按热度按时间sxpgvts31#
c_cpp_properties.json
控制IDE中的intellisense解析包含文件的位置。IDE和生成任务是独立的,因此在VS代码中独立配置和操作。问题的解决方案是将include路径添加到
tasks.json
文件中,如下所示:gwo2fgha2#
我通过为
glib
添加两个路径(如pkg-config
所报告的那样),设法使IntelliSense正常工作:.vscode/c_cpp_属性.json
a9wyjsp73#
什么解决了它为我是只键入文件夹路径没有/* 或/**然后它提示我,如果我想启用智能感知为这个文件夹,我允许它,它的工作。
xj3cbfub4#
我遇到了同样的问题,这是由于
c_cpp_properties.json
文件中的configurationProvider
选项指向了一个禁用的makefile-tools
插件。makefile-tools
插件正确地生成了包含路径列表,但这些路径没有包含在Intellisense的包含路径最终列表中,因为插件被禁用了。在我的情况下,解决方案是删除配置选项或启用makefile-tools
插件。