CMake 构建 OpenCV、PCL项目 vscode include 去波浪线

文章目录

  • CMake 构建 OpenCV、PCL项目
  • 找不到文件pcl/visualization/cloud_viewer.h
  • vscode include 去波浪线

CMake 构建 OpenCV、PCL项目

项目cmake时出现错误

CMake Error: Boost not Found(common is required but boost was not found)

解决方法:

$locate libboost_system

找到Boost_LIBRARY路径,CMakeLists.txt内添加

set(Boost_LIBRARY_DIR /usr/lib/x86_64-linux-gnu/)

最后,完整的CMakeLists.txt:

CMAKE_MINIMUM_REQUIRED(VERSION 2.6)

# 项目名称
PROJECT(Test)

# 设置boost路径
set(Boost_LIBRARY_DIR "/usr/lib/x86_64-linux-gnu/")

# 找opencv package
find_package(OpenCV REQUIRED) 

# 设置PCL路径
set(PCL_DIR "/usr/local/include/pcl-1.9")
find_package(PCL 1.9 REQUIRED)
include_directories(${PCL_INCLUDE_DIRS})
link_directories(${PCL_LIBRARY_DIRS})
add_definitions(${PCL_DEFINITIONS})

set(CMAKE_C_COMPILER "gcc")
set(CMAKE_CXX_COMPILER "g++")
set(CMAKE_CXX_STANDARD 11)

# 根目录/代码路径
aux_source_directory(. DIR_MAIN)

# dubug 模式
set (CMAKE_CXX_FLAGS  "${CMAKE_CXX_FLAGS} -g")

# 编译成可执行文件
set(EXECUTABLE_OUTPUT_PATH ${PROJECT_SOURCE_DIR}/build) 
add_executable(Test PolyocularReconstruction.cpp)

# 链接opencv、PCL库
target_link_libraries(Test ${OpenCV_LIBS})
target_link_libraries(Test ${PCL_LIBRARIES})

参考:
https://blog.csdn.net/linear_luo/article/details/52650845
https://blog.csdn.net/xiangxianghehe/article/details/79028186

找不到文件pcl/visualization/cloud_viewer.h

#include 出错 说是找不到这个文件
去pcl安装位置看了下,确实找不到visualization文件夹,是安装pcl时没有勾选vtk的问题,所以,重装pcl。

  1. 卸载pcl
    在pcl编译的文件夹中,
cd pcl
cd build 
sudo make uninstall 
cd ..
rm -rf build

把装好了的pcl卸了

  1. 安装vtk
 sudo apt install tcl-vtk
 sudo apt-get install libvtk6.2 libvtk6.2-qt libvtk6-dev
  1. 重新编译pcl
cd pcl
mkdir build
cd build
cmake-gui 
// 也可以:cmake -DCMAKE_BUILD_TYPE=None -DBUILD_GPU=ON -DBUILD_apps=ON -DBUILD_examples=ON
make // 可以make -j8 加速,但我的电脑容易崩。。。直接make最稳定
sudo make install

cmake选项

WITH_VTK=ON
CMAKE_BUILD_TYPE=None
BUILD_GPU=ON
BUILD_apps=ON
BUILD_examples=ON

最后 在/usr/local/include/pcl-1.9/pcl/下,终于找到了visualization文件夹

参考: https://blog.csdn.net/weixin_39750861/article/details/92703412

vscode include 去波浪线

当cpp文件中加入

#include 
#include 

后, 这部分会加波浪线。
解决办法:

  1. F1
  2. C/C++: edit configurations(JSON)
    生成 c_cpp_properties.json 文件
  3. 修改 c_cpp_properties.json文件,如下
{
    "configurations": [
        {
            "name": "Linux",
            "includePath": [
                "${workspaceFolder}/**",
                "/usr/local/include/pcl-1.9" /////////添加pcl路径
            ],
            "defines": [],
            "compilerPath": "/usr/bin/gcc",
            "cStandard": "c11",
            "cppStandard": "c++17",
            "intelliSenseMode": "clang-x64"
        }
    ],
    "version": 4
}

CMake 构建 OpenCV、PCL项目 vscode include 去波浪线_第1张图片
参考:https://blog.csdn.net/zhulinmanbu114/article/details/90236490

你可能感兴趣的:(opencv,vscode,pcl)