c++ 链接器中的PCL未定义引用

qyyhg6bp  于 2023-05-08  发布在  其他
关注(0)|答案(1)|浏览(181)

我正在尝试使用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上)

dwbf0jvd

dwbf0jvd1#

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

相关问题