Garhoode 2022-12-16 17:47 采纳率: 0%
浏览 19
已结题

MacOS的VScode如何正常运行PCL库

问题背景

在MacOS上安装了VScode,在VScode编译完成了“helloworld.cpp“的基础c++代码运行。现希望在vscode上能够顺利运行PCL库的相关代码。
运行PCL相关代码时,始终编译报错。

相关情况

以下是c_cpp_properties.json文件:


    "configurations": [
        {
            "name": "Mac",
            "includePath": [
                "${workspaceFolder}/**",
                "/opt/homebrew/Cellar/**",
                "/opt/homebrew/include/",
                "/opt/homebrew/Cellar/pcl/1.12.1_5/include/",
                "/opt/homebrew/Cellar/pcl/1.12.1_5/include/pcl-1.12",
                "/opt/homebrew/Cellar/eigen/3.4.0_1/include/eigen3",
                "/opt/homebrew/Cellar/vtk/9.2.2/include/",
                "/opt/homebrew/Cellar/boost/1.80.0/include/",
                "/opt/homebrew/Cellar/vtk/9.2.2/include/vtk-9.2",
                "/opt/homebrew/Cellar/eigen/3.4.0_1/include/"
            ],
            "defines": [],
            "macFrameworkPath": [
                "/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/System/Library/Frameworks"
            ],
            "compilerPath": "/usr/bin/clang",
            "cStandard": "c17",
            "cppStandard": "c++17",
            "intelliSenseMode": "macos-clang-arm64"
        }
    ],
    "version": 4
}

以下是task.json文件

{
    "tasks": [
        {
            "type": "cppbuild",
            "label": "C/C++: clang++ 生成活动文件",
            "command": "/usr/bin/clang++",
            "args": [
                "-g",
                "${workspaceFolder}/${fileBasename}",
                "-I",
                "/opt/homebrew/Cellar/pcl/1.12.1_5/include/pcl-1.12",
                "-I",
                "/opt/homebrew/Cellar/eigen/3.4.0_1/include/eigen3",
                "-I",
                "/opt/homebrew/Cellar/vtk/9.2.2/include/",
                "-I",
                "/opt/homebrew/Cellar/boost/1.80.0/include/",
                "-I",
                "/opt/homebrew/Cellar/qhull/include/qhull",
                "-I",
                "/opt/homebrew/include/flann",
                "-L",
                "/opt/homebrew/Cellar/pcl/1.12.1_5/lib/",
                "-L",
                "/opt/homebrew/Cellar/vtk/9.2.2/lib/",
                "-L",
                "/opt/homebrew/Cellar/boost/1.80.0/lib/",
                "-L",
                "/opt/homebrew/lib/",
                "-L",
                "/opt/homebrew/Cellar/qhull/lib/",
                "-L",
                "/opt/homebrew/Cellar/flann/1.9.1_6/lib/",
                "-L",
                "/usr/lib/",
                "-o",
                "${workspaceFolder}/${fileBasenameNoExtension}.out"
            ],
            "options": {
                "cwd": "${fileDirname}"
            },
            "problemMatcher": [
                "$gcc"
            ],
            "group": {
                "kind": "build",
                "isDefault": true
            },
            "detail": "调试器生成的任务。"
        },
    ],
    "version": "2.0.0"
}

以下是简单的PCL的c++代码

#include <iostream>
#include <pcl/io/pcd_io.h>
#include <pcl/point_types.h>
using namespace std;

int
main(int argc, char** argv)
{
    // --------------------加载源点云-----------------------
    pcl::PointCloud<pcl::PointXYZ>::Ptr source(new pcl::PointCloud<pcl::PointXYZ>);
    pcl::io::loadPCDFile<pcl::PointXYZ>("source.pcd", *source);
    cout << "从源点云中读取 " << source->size() << " 个点" << endl;
    return (0);
}

运行结果及详细报错内容

运行后报错

img

通过“转到定义”,发现定义的.h文件中也存在大量报错,如下图:

img

归结原因应该是头文件和库链接没到位
请问一下如何能够正确设置.json文件,以达到调试以及顺利运行的目的

  • 写回答

0条回答 默认 最新

    报告相同问题?

    问题事件

    • 系统已结题 12月24日
    • 创建了问题 12月16日

    悬赏问题

    • ¥15 35114 SVAC视频验签的问题
    • ¥15 impedancepy
    • ¥15 在虚拟机环境下完成以下,要求截图!
    • ¥15 求往届大挑得奖作品(ppt…)
    • ¥15 如何在vue.config.js中读取到public文件夹下window.APP_CONFIG.API_BASE_URL的值
    • ¥50 浦育平台scratch图形化编程
    • ¥20 求这个的原理图 只要原理图
    • ¥15 vue2项目中,如何配置环境,可以在打完包之后修改请求的服务器地址
    • ¥20 微信的店铺小程序如何修改背景图
    • ¥15 UE5.1局部变量对蓝图不可见