除了PCL(点云库)之外,VSCode C++IntelliSense工作正常



关于SO本身,已经有很多关于VSCode IntelliSense的问题,例如,que1、que2、que3等。然而,他们主要谈论IntelliSense在一般情况下不起作用;不为STL工作;等等

另一方面,在我的情况下,我已经在使用Microsoft的VSCode C/C++扩展,IntelliSense可以很好地用于所有不同的内置类、函数、STL等。但是,当涉及到PCL(点云库(时,不知怎的,神秘地,IntelliSenses不起作用。

如果您熟悉PCL,那么一定知道它的大多数语法都太大了。由于IntelliSense不起作用,如果你在键入每一个字符时不集中注意力,例如,就很有可能出现拼写错误

pcl::PointCloud<pcl::PointXYZRGB>::Ptr point_cloud_ptr (new pcl::PointCloud<pcl::PointXYZRGB>);

事实上,即使是那些变量和函数的自动完成也不起作用——也就是说,从上面的例子来看,每次我想使用point_cloud_ptr时,我都必须手动键入它的每一个字符

那么,我该怎么解决这个问题呢?还是PCL不可能?

注意:我在Ubuntu 16Ubuntu18上都面临这个问题。我使用sudo apt install libpcl-dev安装了PCL,头文件位于/usr/include/目录中。

在GitHub上尝试了不同的东西并获得了Microsoft VSCode(和C/C++扩展(团队的帮助后,IntelliSense似乎不起作用可能是因为扩展无法找到PCL头。

在Ubuntu的情况下,PCL标头通常存储在/usr/include/pcl-<version>中。在我的Ubuntu 18.04中,我有pcl-1.8。因此,理想情况下,在c_cpp_properties.json文件的"includePath"下添加"/usr/include/pcl-1.8/**"应该可以工作。例如

{
    "configurations": [
        {
            .
            .
            "includePath": [
                "${workspaceFolder}/**",
                "/usr/include/pcl-1.8/**"
            ],
            .
            .
            .
        }
    ],
    "version": 4
}

"/usr/include/pcl-1.8/**"中,**用于/usr/include/pcl-1.8/目录下的递归搜索。然而,当我发布这个问题时(我想到今天为止也是如此(,它不起作用。它无法遍历pcl-<version>目录下的子目录。因此,替代解决方案如下:


解决方案01:(如果只想将更改应用于当前项目,请使用此解决方案(

打开C/C++扩展配置文件:c_cpp_properties.json(在Linux上,按Ctrl+Shift+p并选择C/C++: Edit Configurations (JSON)(

现在,由于递归搜索不起作用,另一种方法是指定includePath:下的所有子目录

{
    "configurations": [
        {
            .
            .
            "includePath": [
                "${workspaceFolder}/**",
                "/usr/include/eigen3",
                "/usr/include/pcl-1.8",
                "/usr/include/pcl-1.8/pcl",
                "/usr/include/pcl-1.8/pcl/2d",
                "/usr/include/pcl-1.8/pcl/apps",
                "/usr/include/pcl-1.8/pcl/common",
                "/usr/include/pcl-1.8/pcl/compression",
                "/usr/include/pcl-1.8/pcl/console",
                "/usr/include/pcl-1.8/pcl/features",
                "/usr/include/pcl-1.8/pcl/filters",
                "/usr/include/pcl-1.8/pcl/geometry",
                "/usr/include/pcl-1.8/pcl/impl",
                "/usr/include/pcl-1.8/pcl/in_hand_scanner",
                "/usr/include/pcl-1.8/pcl/io",
                "/usr/include/pcl-1.8/pcl/kdtree",
                "/usr/include/pcl-1.8/pcl/keypoints",
                "/usr/include/pcl-1.8/pcl/ml",
                "/usr/include/pcl-1.8/pcl/modeler",
                "/usr/include/pcl-1.8/pcl/octree",
                "/usr/include/pcl-1.8/pcl/outofcore",
                "/usr/include/pcl-1.8/pcl/people",
                "/usr/include/pcl-1.8/pcl/range_image",
                "/usr/include/pcl-1.8/pcl/recognition",
                "/usr/include/pcl-1.8/pcl/registration",
                "/usr/include/pcl-1.8/pcl/ros",
                "/usr/include/pcl-1.8/pcl/sample_consensus",
                "/usr/include/pcl-1.8/pcl/search",
                "/usr/include/pcl-1.8/pcl/segmentation",
                "/usr/include/pcl-1.8/pcl/stereo",
                "/usr/include/pcl-1.8/pcl/surface",
                "/usr/include/pcl-1.8/pcl/tracking",
                "/usr/include/pcl-1.8/pcl/visualization"
            ],
            .
            .
            .
        }
    ],
    "version": 4
}

解决方案02:(如果您想在所有项目中全局应用更改,请使用此解决方案(

由于C/C++配置文件:c_cpp_properties.json特定于每个项目,因此编辑只会将更改应用于当前项目。因此,要在所有项目中应用更改,必须先更新settings.json,然后更新c_cpp_properies.json

打开settings.json并添加以下文本:

    "C_Cpp.default.includePath": [
        "/usr/include/eigen3",
        "/usr/include/pcl-1.8",
        "/usr/include/pcl-1.8/pcl",
        "/usr/include/pcl-1.8/pcl/2d",
        "/usr/include/pcl-1.8/pcl/apps",
        "/usr/include/pcl-1.8/pcl/common",
        "/usr/include/pcl-1.8/pcl/compression",
        "/usr/include/pcl-1.8/pcl/console",
        "/usr/include/pcl-1.8/pcl/features",
        "/usr/include/pcl-1.8/pcl/filters",
        "/usr/include/pcl-1.8/pcl/geometry",
        "/usr/include/pcl-1.8/pcl/impl",
        "/usr/include/pcl-1.8/pcl/in_hand_scanner",
        "/usr/include/pcl-1.8/pcl/io",
        "/usr/include/pcl-1.8/pcl/kdtree",
        "/usr/include/pcl-1.8/pcl/keypoints",
        "/usr/include/pcl-1.8/pcl/ml",
        "/usr/include/pcl-1.8/pcl/modeler",
        "/usr/include/pcl-1.8/pcl/octree",
        "/usr/include/pcl-1.8/pcl/outofcore",
        "/usr/include/pcl-1.8/pcl/people",
        "/usr/include/pcl-1.8/pcl/range_image",
        "/usr/include/pcl-1.8/pcl/recognition",
        "/usr/include/pcl-1.8/pcl/registration",
        "/usr/include/pcl-1.8/pcl/ros",
        "/usr/include/pcl-1.8/pcl/sample_consensus",
        "/usr/include/pcl-1.8/pcl/search",
        "/usr/include/pcl-1.8/pcl/segmentation",
        "/usr/include/pcl-1.8/pcl/stereo",
        "/usr/include/pcl-1.8/pcl/surface",
        "/usr/include/pcl-1.8/pcl/tracking",
        "/usr/include/pcl-1.8/pcl/visualization"
    ]

打开c_cpp_properties.json并更新includePath:

{
    "configurations": [
        {
            .
            .
            "includePath": [
                "${workspaceFolder}/**",
                "${default}"
            ],
            .
            .
            .
        }
    ],
  
  "version": 4
}

p.S.我在微软的C/C++扩展的官方GitHub问题页面上问了同样的问题,最终找到了我上面提到的解决方案(但不是理想的解决方案(。

以下是获取更多信息的链接:https://github.com/microsoft/vscode-cpptools/issues/5843

因为VSCode总是告诉我它找不到像pcl/PCLHeader.h这样的依赖项。所以我试着把/usr/include/pcl-1.10/pcl复制到/usr/include/,结果成功了。

相关内容

  • 没有找到相关文章

最新更新