zoukankan      html  css  js  c++  java
  • CMake入门之创建一个基于PCL的最小工程

         最近在学习PCL,借助Cmake可省去繁琐的添加包含目录和依赖库操作。

         一个典型的CMakeLists.txt内容通常为:

    1 cmake_minimum_required(VERSION 2.6 FATAL_ERROR)
    2 project(MY_GRAND_PROJECT)
    3 find_package(PCL 1.3 REQUIRED COMPONENTS common io)
    4 include_directories(${PCL_INCLUDE_DIRS})
    5 link_directories(${PCL_LIBRARY_DIRS})
    6 add_definitions(${PCL_DEFINITIONS})
    7 add_executable(pcd_write_test pcd_write.cpp)
    8 target_link_libraries(pcd_write_test ${PCL_COMMON_LIBRARIES} ${PCL_IO_LIBRARIES})

    CMake文件第一行:

    cmake_minimum_required(VERSION 2.6 FATAL_ERROR)

    这一句对Cmake来说是必需的,需要在这句添加满足你对Cmake特征需求的最小版本号。

    接下来一句:

    project(MY_GRAND_PROJECT)

    建立一个工程,括号内MY_GRAND_PROJECT为自己工程的名字。

    find_package(PCL 1.3 REQUIRED COMPONENTS common io)

    由于我们是建立一个PCL项目,因此需要找到对应的PCL package,如果找不到则项目创建失败。除此之外,我们还可以使用一下方式:

    1)如果是需要某一个PCL的某一个组件: find_package(PCL 1.3 REQUIRED COMPONENTS io)

    2)如果是几个组件:find_package(PCL 1.3 REQUIRED COMPONENTS io common)

    3)如果需要整个安装包:find_package(PCL 1.3 REQUIRED)

    include_directories(${PCL_INCLUDE_DIRS})
    link_directories(${PCL_LIBRARY_DIRS})
    add_definitions(${PCL_DEFINITIONS})

    当PCL安装包找到之后,就需要添加对应的包含目录和依赖库了。我们需要设置几个相关的变量:

    • PCL_FOUND: set to 1 if PCL is found, otherwise unset
    • PCL_INCLUDE_DIRS: set to the paths to PCL installed headers and the dependency headers
    • PCL_LIBRARIES: set to the file names of the built and installed PCL libraries
    • PCL_LIBRARY_DIRS: set to the paths to where PCL libraries and 3rd party dependencies reside
    • PCL_VERSION: the version of the found PCL
    • PCL_COMPONENTS: lists all available components
    • PCL_DEFINITIONS: lists the needed preprocessor definitions and compiler flags
    add_executable(pcd_write_test pcd_write.cpp)

    接下来这需要从pcd_write.cpp文件生成一个名为pcd_write_test的可执行文件。

    在生成对应的exe文件之后,需要调用PCL相关函数,因此需要添加相应链接库:

    target_link_libraries(pcd_write_test ${PCL_COMMON_LIBRARIES} ${PCL_IO_LIBRARIES})

    至此,就可以使用CMake生成自己的工程了。

  • 相关阅读:
    centos7 /etc/rc.local需要chmod +x /etc/rc.d/rc.local
    epel源
    yum 源
    socket
    CentOS 7使用systemctl如何补全服务名称
    keepalive脑裂的处理,从节点发现访问的虚拟IP就报警,同时尝试发送内容到主节点服务器关闭keepalive和nginx,或者关机
    nginx的 keepalive_timeout参数是一个请求完成之后还要保持连
    kickstart安装步骤
    kickstart
    因客户机IP与服务器IP不在同一网段导致无盘客户机开机卡tftp,提示:PXE-E11: ARP timeout
  • 原文地址:https://www.cnblogs.com/freshmen/p/5828867.html
Copyright © 2011-2022 走看看