使用Bazel构建PCL

时间:2018-07-15 16:26:14

标签: c++ bazel point-cloud-library

如何使用Bazel构建PCL(点云库:https://github.com/PointCloudLibrary/pcl)?我已经成功使用OpenCV,如此处所述:Building OpenCV code using Bazel

当我对PCL执行相同的步骤时,会出现以下错误:

错误:

ERROR: /home/thomas/Projects/prome/bazel/lib/BUILD:15:1: C++ compilation of rule '//lib:hello-pcl' failed (Exit 1).
lib/pcl.cpp:3:10: fatal error: pcl/common/common_headers.h: No such file or directory
 #include <pcl/common/common_headers.h>
          ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~
compilation terminated.
Target //main:hello-world failed to build

我的系统:

  • Ubuntu 18.04,64位
  • 编译器:clang版本6.0.0-1ubuntu2
  • Bazel:构建标签:0.15.0

我的文件夹结构:

├── lib
│   ├── BUILD
│   ├── ...
│   ├── pcl.cpp
│   └── pcl.h
├── main
│   ├── BUILD
│   ├── ..
│   └── hello-world.cc
├── opencv.BUILD
├── pcl.BUILD
└── WORKSPACE

我的工作空间(openCV有效):

new_local_repository(
    name = "opencv",
    path = "/usr/local",
    build_file = "opencv.BUILD",
)

new_local_repository(
    name = "pcl",
    path = "/usr",
    build_file = "pcl.BUILD"
)

我的个人资料已构建:

cc_library(
    name = "pcl",
    srcs = glob(["lib/x86_64-linux-gnu/*.so"]),
    hdrs = glob(["include/pcl-1.8/pcl/**/*.hpp", "include/pcl-1.8/pcl/**/*.h"]),
    includes = ["include"],
    visibility = ["//visibility:public"],
    linkstatic = 1,
)

我的二进制定义

cc_binary(
    name = "hello-world",
    srcs = ["hello-world.cc"],
    deps = [
        ":hello-greet",
        "//lib:hello-opencv",
        "//lib:hello-pcl",
        "//lib:hello-time",
        "@opencv//:opencv",
        "@pcl//:pcl",
    ],
)

“ dpkg -L libpcl-dev”的结果

https://github.com/tom-010/bazel-test/blob/master/dpgk_output

最后,失败的cpp代码(/lib/pcl.cpp):

#include "pcl.h"

#include <pcl/common/common_headers.h>
#include <pcl/visualization/pcl_visualizer.h>

void hello_pcl() {
    // pcl stuff....
}

我在一个额外的项目中模拟了该错误,并将其上传到这里:https://github.com/tom-010/bazel-test 该项目是使用上述系统构建的。

没有包含的错误

当我删除#include-headers时:

#include "pcl.h"

void hello_pcl() {
    // pcl stuff....
}

我收到以下错误:

[980 / 981] Linking main/hello-world
ERROR: /home/thomas/Projects/prome/bazel/main/BUILD:7:1: Linking of rule '//main:hello-world' failed (Exit 1).
/usr/bin/x86_64-linux-gnu-ld.gold: error: cannot find -lp11-kit-proxy
/usr/bin/x86_64-linux-gnu-ld.gold: error: cannot find -lpreloadable_libintl
bazel-out/k8-fastbuild/bin/_solib_k8/_U@pcl_S_S_Cpcl___Uexternal_Spcl_Slib_Sx86_U64-linux-gnu/libthread_db.so: error: undefined reference to 'ps_pdread'
bazel-out/k8-fastbuild/bin/_solib_k8/_U@pcl_S_S_Cpcl___Uexternal_Spcl_Slib_Sx86_U64-linux-gnu/libthread_db.so: error: undefined reference to 'ps_lgetregs'
bazel-out/k8-fastbuild/bin/_solib_k8/_U@pcl_S_S_Cpcl___Uexternal_Spcl_Slib_Sx86_U64-linux-gnu/libthread_db.so: error: undefined reference to 'ps_lsetfpregs'
bazel-out/k8-fastbuild/bin/_solib_k8/_U@pcl_S_S_Cpcl___Uexternal_Spcl_Slib_Sx86_U64-linux-gnu/libthread_db.so: error: undefined reference to 'ps_lgetfpregs'
bazel-out/k8-fastbuild/bin/_solib_k8/_U@pcl_S_S_Cpcl___Uexternal_Spcl_Slib_Sx86_U64-linux-gnu/libthread_db.so: error: undefined reference to 'ps_getpid'
bazel-out/k8-fastbuild/bin/_solib_k8/_U@pcl_S_S_Cpcl___Uexternal_Spcl_Slib_Sx86_U64-linux-gnu/libthread_db.so: error: undefined reference to 'ps_lsetregs'
bazel-out/k8-fastbuild/bin/_solib_k8/_U@pcl_S_S_Cpcl___Uexternal_Spcl_Slib_Sx86_U64-linux-gnu/libthread_db.so: error: undefined reference to 'ps_pglobal_lookup'
bazel-out/k8-fastbuild/bin/_solib_k8/_U@pcl_S_S_Cpcl___Uexternal_Spcl_Slib_Sx86_U64-linux-gnu/libthread_db.so: error: undefined reference to 'ps_pdwrite'
collect2: error: ld returned 1 exit status
Target //main:hello-world failed to build

如果我从二进制定义的deps部分中删除此行,则不会发生这种情况:

# "@pcl//:pcl",

在我的CMake-Projekt中已经可以使用的PCL:

find_package(PCL 1.2 REQUIRED)
include_directories(${PCL_INCLUDE_DIRS})
link_directories(${PCL_LIBRARY_DIRS})
add_definitions(${PCL_DEFINITIONS})

set(CLOUD_VIEWER_SOURCES
        Viewer.cpp
        Viewer.h)

add_library(cloud_viewer ${CLOUD_VIEWER_SOURCES})
target_link_libraries(cloud_viewer PRIVATE agent ${PCL_LIBRARIES})
target_include_directories(cloud_viewer PUBLIC ${CMAKE_CURRENT_SOURCE_DIR})

0 个答案:

没有答案
相关问题