Josh
Josh

Reputation: 2869

Unable to compile a QT app utilising PCL Visualizer due to missing VTK/MPI C component

I'm trying to build a demo QT application using the Point Cloud Library (PCL) and its provided visualiser component (#include <pcl/visualization/pcl_visualizer.h>). I'm using Cmake for the build system. Cmake finds PCL without issue, but trying to include that header throws an error about VTK smart pointers.

I'm running Kubuntu 23.04 and both PCL (libpcl-dev) and VTK (libvtk9-dev) have been installed via apt. I've also installed MPI (mpich openmpi-bin openmpi-common openmpi-doc libopenmpi-dev). mpicc and mpicxx are present in /usr/bin and I've tried passing them as Cmake config options (-DMPI_C_COMPILER:PATH=/usr/bin/mpicc), but I don't really know where the problem is coming from. If possible I would prefer not to build VTK from source.

When I try to include VTK in my CMakeLists, I get an error about MPI components for VTK:

cmake_minimum_required(VERSION 3.12)

# Set the project name
project(VTKExample)

# Find the VTK package
find_package(VTK REQUIRED)

# Include the VTK directories
include(${VTK_USE_FILE})

# Add the executable
add_executable(VTKExample main.cpp)

# Link the VTK libraries
target_link_libraries(VTKExample ${VTK_LIBRARIES})

/usr/share/cmake-3.27/Modules/FindPackageHandleStandardArgs.cmake:230: error: Could NOT find MPI (missing: MPI_C_FOUND C) (found version "3.1")
Reason given by package: MPI component 'C' was requested, but language C is not enabled.
/usr/share/cmake-3.27/Modules/FindPackageHandleStandardArgs.cmake:600 (_FPHSA_FAILURE_MESSAGE)
/usr/share/cmake-3.27/Modules/FindMPI.cmake:1837 (find_package_handle_standard_args) CMakeLists.txt:22 (find_package)

This works, but fails to compile due to a missing VTK include (but confirms that PCL is found OK and that MPI seems partially installed):

find_package(MPI COMPONENTS CXX REQUIRED)
find_package(PCL REQUIRED)

This does not:

find_package(VTK REQUIRED)
find_package(PCL REQUIRED)

Nor does this:

find_package(MPI COMPONENTS C CXX REQUIRED)
find_package(PCL REQUIRED)

Some googling suggests that there was an issue with FindMPI in older versions of Cmake, but that this was fixed (3.15 seems to be problematic).

Example code (old though): https://pcl.readthedocs.io/projects/tutorials/en/latest/qt_visualizer.html


I had ChatGPT make me a minimal example that loads the visualiser, and this does work (compiles and displays):

#include <pcl/visualization/pcl_visualizer.h>
#include <pcl/point_types.h>
#include <pcl/io/pcd_io.h>

#include <cmath>

constexpr float deg2rad(float degrees) {
    return degrees * M_PI / 180.0f;
}

int main(int, char *[])
{
    // PCL part: Create and visualize some dummy point cloud data
    pcl::PointCloud<pcl::PointXYZ>::Ptr cloud(new pcl::PointCloud<pcl::PointXYZ>);

    // Fill the cloud with some dummy data
    for (float z = -1.0; z <= 1.0; z += 0.05)
    {
        for (float angle = 0.0; angle <= 360.0; angle += 5.0)
        {
            pcl::PointXYZ point;
            point.x = 0.5 * cosf(deg2rad(angle));
            point.y = 0.5 * sinf(deg2rad(angle));
            point.z = z;
            cloud->points.push_back(point);
        }
    }
    cloud->width = cloud->points.size();
    cloud->height = 1;
    cloud->is_dense = true;

    // Create a PCLVisualizer
    pcl::visualization::PCLVisualizer::Ptr viewer(new pcl::visualization::PCLVisualizer("3D Viewer"));
    viewer->setBackgroundColor(0, 0, 0);
    viewer->addPointCloud<pcl::PointXYZ>(cloud, "sample cloud");
    viewer->setPointCloudRenderingProperties(pcl::visualization::PCL_VISUALIZER_POINT_SIZE, 1, "sample cloud");
    viewer->addCoordinateSystem(1.0);
    viewer->initCameraParameters();

    // Start visualization with interactivity
    while (!viewer->wasStopped())
    {
        viewer->spinOnce(1, true);
    }

    return 0;
}

CMake Warning (dev) at /usr/lib/x86_64-linux-gnu/cmake/pcl/PCLConfig.cmake:147 (find_package):
  Policy CMP0144 is not set: find_package uses upper-case <PACKAGENAME>_ROOT
  variables.  Run "cmake --help-policy CMP0144" for policy details.  Use the
  cmake_policy command to set the policy and suppress this warning.

  CMake variable EIGEN_ROOT is set to:

    /usr/include/eigen3

  For compatibility, find_package is ignoring the variable, but code in a
  .cmake module might still use it.
Call Stack (most recent call first):
  /usr/lib/x86_64-linux-gnu/cmake/pcl/PCLConfig.cmake:300 (find_eigen)
  /usr/lib/x86_64-linux-gnu/cmake/pcl/PCLConfig.cmake:544 (find_external_library)
  CMakeLists.txt:10 (find_package)
This warning is for project developers.  Use -Wno-dev to suppress it.

-- Eigen found (include: /usr/include/eigen3, version: 3.4.0)
-- OpenNI found (version: 1.5.4.0, include: /usr/include/ni, lib: /usr/lib/libOpenNI.so;libusb::libusb)
-- OpenNI2 found (version: 2.2.0.33, include: /usr/include/openni2, lib: /usr/lib/x86_64-linux-gnu/libOpenNI2.so;libusb::libusb)
** WARNING ** io features related to pcap will be disabled
-- Eigen found (include: /usr/include/eigen3, version: 3.4.0)
CMake Warning (dev) at /usr/lib/x86_64-linux-gnu/cmake/pcl/Modules/FindFLANN.cmake:44 (find_package):
  Policy CMP0144 is not set: find_package uses upper-case <PACKAGENAME>_ROOT
  variables.  Run "cmake --help-policy CMP0144" for policy details.  Use the
  cmake_policy command to set the policy and suppress this warning.

  CMake variable FLANN_ROOT is set to:

    /usr

  For compatibility, find_package is ignoring the variable, but code in a
  .cmake module might still use it.
Call Stack (most recent call first):
  /usr/lib/x86_64-linux-gnu/cmake/pcl/PCLConfig.cmake:257 (find_package)
  /usr/lib/x86_64-linux-gnu/cmake/pcl/PCLConfig.cmake:302 (find_flann)
  /usr/lib/x86_64-linux-gnu/cmake/pcl/PCLConfig.cmake:544 (find_external_library)
  CMakeLists.txt:10 (find_package)
This warning is for project developers.  Use -Wno-dev to suppress it.

-- Found flann version 1.9.2
-- OpenNI found (version: 1.5.4.0, include: /usr/include/ni, lib: /usr/lib/libOpenNI.so;libusb::libusb)
-- OpenNI2 found (version: 2.2.0.33, include: /usr/include/openni2, lib: /usr/lib/x86_64-linux-gnu/libOpenNI2.so;libusb::libusb)
-- looking for PCL_COMMON
-- looking for PCL_OCTREE
-- looking for PCL_IO
-- looking for PCL_KDTREE
-- looking for PCL_GEOMETRY
-- looking for PCL_SEARCH
-- looking for PCL_VISUALIZATION
CMake Deprecation Warning at /usr/lib/x86_64-linux-gnu/cmake/vtk-9.1/vtk-use-file-deprecated.cmake:1 (message):
  The `VTK_USE_FILE` is no longer used starting with 8.90.
Call Stack (most recent call first):
  CMakeLists.txt:13 (include)


-- Configuring done (0.7s)
-- Generating done (0.0s)
-- Build files have been written to: /home/josh/code/vtk-test/build

So it looks like potentially an issue with the CMake config in Qt somewhere?

Upvotes: 1

Views: 230

Answers (1)

Josh
Josh

Reputation: 2869

Turns out there's a simple answer here, the default configuration that Qt Creator provides does not add C support. I found this out by checking the CMakeCache for the Qt and standalone test and noticed that the Qt output didn't have a C compiler set (and despite a lot of attempts in the Kit configuration, wouldn't let me add one). In CMakeLists.txt:

project(project VERSION 0.1 LANGUAGES CXX)

one needs to add:

project(project VERSION 0.1 LANGUAGES C CXX)

Upvotes: 1

Related Questions