链接器中的 PCL 未定义引用

PCL undefined reference in linker

提问人:bipin krishna 提问时间:5/5/2023 最后编辑:Botjebipin krishna 更新时间:5/5/2023 访问量:269

问:

我正在尝试从点云数据中使用 SurfaceReconstruction,这是我的代码

#include <pcl/point_types.h>
#include <pcl/io/pcd_io.h>
#include <pcl/io/ply_io.h>
#include <pcl/surface/marching_cubes_hoppe.h>

int main(int argc, char** argv)
{
  // Open the input text file
  std::ifstream input_file("prereq/model.txt");

  // Create a PCL point cloud object to store the points
  pcl::PointCloud<pcl::PointXYZ>::Ptr cloud(new pcl::PointCloud<pcl::PointXYZ>);

  // Parse the text file line by line to extract the point coordinates
  std::string line;
  while (std::getline(input_file, line))
  {
    std::istringstream iss(line);
    float x, y, z;
    if (!(iss >> x >> y >> z))
    {
      // Handle parsing error
      break;
    }
    // Add the point to the PCL point cloud object
    cloud->push_back(pcl::PointXYZ(x, y, z));
  }

   // Create a set of triangular meshes using the Marching Cubes algorithm
  pcl::PolygonMesh triangles;
  pcl::MarchingCubesHoppe<pcl::PointXYZ> mc;
  mc.setInputCloud(cloud);
  mc.setIsoLevel(0.025);
  mc.reconstruct(triangles);

  pcl::io::savePLYFile("output_mesh.ply", triangles);

  return 0;
}

当我尝试使用命令构建它时

g++ hmm.cpp -o a.out -I/usr/include/pcl-1.12/ -I/usr/include/eigen3 -lpcl_common -lpcl_io -lpcl_surface -lpcl_visualization -lpcl_octree -lpcl_recognition -lpcl_segmentation -lpcl_registration -lpcl_tracking -lpcl_search -lpcl_common -lpcl_surface -lpcl_kdtree -lpcl_features -lpcl_filters

它给了我错误

/usr/bin/ld: /tmp/ccPoS1h1.o: in function `main':
hmm.cpp:(.text+0x2d1): undefined reference to `pcl::MarchingCubesHoppe<pcl::PointXYZ>::~MarchingCubesHoppe()'
/usr/bin/ld: hmm.cpp:(.text+0x3ba): undefined reference to `pcl::MarchingCubesHoppe<pcl::PointXYZ>::~MarchingCubesHoppe()'
/usr/bin/ld: /tmp/ccPoS1h1.o:(.data.rel.ro._ZTVN3pcl18MarchingCubesHoppeINS_8PointXYZEEE[_ZTVN3pcl18MarchingCubesHoppeINS_8PointXYZEEE]+0x10): undefined reference to `pcl::MarchingCubesHoppe<pcl::PointXYZ>::~MarchingCubesHoppe()'
/usr/bin/ld: /tmp/ccPoS1h1.o:(.data.rel.ro._ZTVN3pcl18MarchingCubesHoppeINS_8PointXYZEEE[_ZTVN3pcl18MarchingCubesHoppeINS_8PointXYZEEE]+0x18): undefined reference to `pcl::MarchingCubesHoppe<pcl::PointXYZ>::~MarchingCubesHoppe()'
/usr/bin/ld: /tmp/ccPoS1h1.o:(.data.rel.ro._ZTVN3pcl18MarchingCubesHoppeINS_8PointXYZEEE[_ZTVN3pcl18MarchingCubesHoppeINS_8PointXYZEEE]+0x60): undefined reference to `pcl::MarchingCubes<pcl::PointXYZ>::performReconstruction(pcl::PolygonMesh&)'
/usr/bin/ld: /tmp/ccPoS1h1.o:(.data.rel.ro._ZTVN3pcl18MarchingCubesHoppeINS_8PointXYZEEE[_ZTVN3pcl18MarchingCubesHoppeINS_8PointXYZEEE]+0x68): undefined reference to `pcl::MarchingCubes<pcl::PointXYZ>::performReconstruction(pcl::PointCloud<pcl::PointXYZ>&, std::vector<pcl::Vertices, std::allocator<pcl::Vertices> >&)'
/usr/bin/ld: /tmp/ccPoS1h1.o:(.data.rel.ro._ZTVN3pcl18MarchingCubesHoppeINS_8PointXYZEEE[_ZTVN3pcl18MarchingCubesHoppeINS_8PointXYZEEE]+0x70): undefined reference to `pcl::MarchingCubesHoppe<pcl::PointXYZ>::voxelizeData()'
/usr/bin/ld: /tmp/ccPoS1h1.o:(.data.rel.ro._ZTVN3pcl18MarchingCubesHoppeINS_8PointXYZEEE[_ZTVN3pcl18MarchingCubesHoppeINS_8PointXYZEEE]+0x78): undefined reference to `pcl::MarchingCubes<pcl::PointXYZ>::getGridValue(Eigen::Matrix<int, 3, 1, 0, 3, 1>)'
/usr/bin/ld: /tmp/ccPoS1h1.o:(.data.rel.ro._ZTVN3pcl13MarchingCubesINS_8PointXYZEEE[_ZTVN3pcl13MarchingCubesINS_8PointXYZEEE]+0x60): undefined reference to `pcl::MarchingCubes<pcl::PointXYZ>::performReconstruction(pcl::PolygonMesh&)'
/usr/bin/ld: /tmp/ccPoS1h1.o:(.data.rel.ro._ZTVN3pcl13MarchingCubesINS_8PointXYZEEE[_ZTVN3pcl13MarchingCubesINS_8PointXYZEEE]+0x68): undefined reference to `pcl::MarchingCubes<pcl::PointXYZ>::performReconstruction(pcl::PointCloud<pcl::PointXYZ>&, std::vector<pcl::Vertices, std::allocator<pcl::Vertices> >&)'
/usr/bin/ld: /tmp/ccPoS1h1.o:(.data.rel.ro._ZTVN3pcl13MarchingCubesINS_8PointXYZEEE[_ZTVN3pcl13MarchingCubesINS_8PointXYZEEE]+0x78): undefined reference to `pcl::MarchingCubes<pcl::PointXYZ>::getGridValue(Eigen::Matrix<int, 3, 1, 0, 3, 1>)'
collect2: error: ld returned 1 exit status

我什至尝试过使用CMake

cmake_minimum_required(VERSION 3.10)
project(pointcloud-to-mesh)
find_package(PCL 1.12 REQUIRED COMPONENTS common io surface)
add_executable(pointcloud-to-mesh hmm.cpp)
target_include_directories(pointcloud-to-mesh PRIVATE ${PCL_INCLUDE_DIRS})
target_link_libraries(pointcloud-to-mesh PRIVATE ${PCL_LIBRARIES})

GreedyProjectionTriangulation 和 Poisson 的错误类型相同。

我在这里做错了什么?我使用 apt 安装了 PCL(我在 Ubuntu 上)

C++ 点云库 未定义引用

评论

0赞 anatolyg 5/5/2023
相关

答:

0赞 IBitMyBytes 5/5/2023 #1

不能与 一起使用。您必须使用 or 或 .
另请参阅官方文档:https://pointclouds.org/documentation/classpcl_1_1_marching_cubes_hoppe.html#details
MarchingCubesHoppepcl::PointXYZpcl::PointNormalpcl::PointXYZRGBNormalpcl::PointXYZINormal