编辑:更新代码
我正在使用 PCL 库从点云生成网格。这是基于 PCL 文档中的贪心三角剖分教程的代码:
#include <pcl/point_types.h>
#include <pcl/common/io.h>
#include <pcl/io/ply_io.h>
#include <pcl/search/kdtree.h>
#include <pcl/features/normal_3d.h>
#include <pcl/surface/gp3.h>
#include <pcl/io/obj_io.h>
#include <vector>
int main() {
pcl::PointCloud<pcl::PointXYZ>::Ptr cloud (new pcl::PointCloud<pcl::PointXYZ>);
pcl::PCLPointCloud2 cloud1;
pcl::PCLPointCloud2 cloud2;
pcl::PCLPointCloud2 cloud3;
pcl::io::loadPLYFile("../cam_1_2.ply", cloud1);
pcl::io::loadPLYFile("../cam_2_3.ply", cloud2);
pcl::io::loadPLYFile("../cam_3_4.ply", cloud3);
cloud1 += cloud2 + cloud3;
pcl::fromPCLPointCloud2(cloud1, *cloud);
pcl::NormalEstimation<pcl::PointXYZ, pcl::Normal> n;
pcl::PointCloud<pcl::Normal>::Ptr normals(new pcl::PointCloud<pcl::Normal>);
pcl::search::KdTree<pcl::PointXYZ>::Ptr tree(new pcl::search::KdTree<pcl::PointXYZ>);
tree->setInputCloud(cloud);
n.setInputCloud(cloud);
n.setSearchMethod(tree);
n.setKSearch(20);
n.compute(*normals);
pcl::PointCloud<pcl::PointNormal>::Ptr cloudWithNormals(new pcl::PointCloud<pcl::PointNormal>);
pcl::concatenateFields(*cloud, *normals, *cloudWithNormals);
pcl::search::KdTree<pcl::PointNormal>::Ptr tree2 (new pcl::search::KdTree<pcl::PointNormal>);
tree2->setInputCloud (cloudWithNormals);
pcl::GreedyProjectionTriangulation<pcl::PointNormal> gp3;
pcl::PolygonMesh triangles;
gp3.setSearchRadius(0.025);
gp3.setMu(2.5);
gp3.setMaximumNearestNeighbors(100);
gp3.setMaximumSurfaceAngle(M_PI/4);
gp3.setMinimumAngle(M_PI/18);
gp3.setMaximumAngle(2 * M_PI / 3);
gp3.setNormalConsistency(false);
gp3.setInputCloud(cloudWithNormals);
gp3.setSearchMethod(tree2);
gp3.reconstruct(triangles);
std::vector<int> parts = gp3.getPartIDs();
std::vector<int> states = gp3.getPointStates();
pcl::io::saveOBJFile("../cam_1_2.obj", triangles);
return 0;
}
这是我用来构建这个的 CMakeLists 文件:
cmake_minimum_required(VERSION 3.1 FATAL_ERROR)
project(TestProject)
find_package(PCL 1.12 REQUIRED COMPONENTS common io)
include_directories(${PCL_INCLUDE_DIRS})
link_directories(${PCL_LIBRARY_DIRS})
add_definitions(${PCL_DEFINITIONS})
add_executable(Test main.cpp)
target_link_libraries(Test ${PCL_LIBRARIES} liblz4.so libpthread.so)
这是终端中的 make 输出:
make 2 ↵
Consolidate compiler generated dependencies of target Test
[ 50%] Building CXX object CMakeFiles/Test.dir/main.cpp.o
[100%] Linking CXX executable Test
/usr/bin/ld: CMakeFiles/Test.dir/main.cpp.o: in function `pcl::search::KdTree<pcl::PointXYZ, pcl::KdTreeFLANN<pcl::PointXYZ, flann::L2_Simple<float> > >::KdTree(bool)':
main.cpp:(.text._ZN3pcl6search6KdTreeINS_8PointXYZENS_11KdTreeFLANNIS2_N5flann9L2_SimpleIfEEEEEC2Eb[_ZN3pcl6search6KdTreeINS_8PointXYZENS_11KdTreeFLANNIS2_N5flann9L2_SimpleIfEEEEEC5Eb]+0x5e): undefined reference to `pcl::search::Search<pcl::PointXYZ>::Search(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, bool)'
/usr/bin/ld: CMakeFiles/Test.dir/main.cpp.o: in function `pcl::search::OrganizedNeighbor<pcl::PointXYZ>::OrganizedNeighbor(bool, float, unsigned int)':
main.cpp:(.text._ZN3pcl6search17OrganizedNeighborINS_8PointXYZEEC2Ebfj[_ZN3pcl6search17OrganizedNeighborINS_8PointXYZEEC5Ebfj]+0x66): undefined reference to `pcl::search::Search<pcl::PointXYZ>::Search(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, bool)'
/usr/bin/ld: CMakeFiles/Test.dir/main.cpp.o:(.data.rel.ro._ZTVN3pcl6search17OrganizedNeighborINS_8PointXYZEEE[_ZTVN3pcl6search17OrganizedNeighborINS_8PointXYZEEE]+0x20): undefined reference to `pcl::search::Search<pcl::PointXYZ>::getName[abi:cxx11]() const'
/usr/bin/ld: CMakeFiles/Test.dir/main.cpp.o:(.data.rel.ro._ZTVN3pcl6search17OrganizedNeighborINS_8PointXYZEEE[_ZTVN3pcl6search17OrganizedNeighborINS_8PointXYZEEE]+0x28): undefined reference to `pcl::search::Search<pcl::PointXYZ>::setSortedResults(bool)'
/usr/bin/ld: CMakeFiles/Test.dir/main.cpp.o:(.data.rel.ro._ZTVN3pcl6search17OrganizedNeighborINS_8PointXYZEEE[_ZTVN3pcl6search17OrganizedNeighborINS_8PointXYZEEE]+0x30): undefined reference to `pcl::search::Search<pcl::PointXYZ>::getSortedResults()'
/usr/bin/ld: CMakeFiles/Test.dir/main.cpp.o:(.data.rel.ro._ZTVN3pcl6search17OrganizedNeighborINS_8PointXYZEEE[_ZTVN3pcl6search17OrganizedNeighborINS_8PointXYZEEE]+0x50): undefined reference to `pcl::search::OrganizedNeighbor<pcl::PointXYZ>::nearestKSearch(pcl::PointXYZ const&, int, std::vector<int, std::allocator<int> >&, std::vector<float, std::allocator<float> >&) const'
/usr/bin/ld: CMakeFiles/Test.dir/main.cpp.o:(.data.rel.ro._ZTVN3pcl6search17OrganizedNeighborINS_8PointXYZEEE[_ZTVN3pcl6search17OrganizedNeighborINS_8PointXYZEEE]+0x58): undefined reference to `pcl::search::Search<pcl::PointXYZ>::nearestKSearch(pcl::PointCloud<pcl::PointXYZ> const&, int, int, std::vector<int, std::allocator<int> >&, std::vector<float, std::allocator<float> >&) const'
/usr/bin/ld: CMakeFiles/Test.dir/main.cpp.o:(.data.rel.ro._ZTVN3pcl6search17OrganizedNeighborINS_8PointXYZEEE[_ZTVN3pcl6search17OrganizedNeighborINS_8PointXYZEEE]+0x60): undefined reference to `pcl::search::Search<pcl::PointXYZ>::nearestKSearch(int, int, std::vector<int, std::allocator<int> >&, std::vector<float, std::allocator<float> >&) const'
/usr/bin/ld: CMakeFiles/Test.dir/main.cpp.o:(.data.rel.ro._ZTVN3pcl6search17OrganizedNeighborINS_8PointXYZEEE[_ZTVN3pcl6search17OrganizedNeighborINS_8PointXYZEEE]+0x68): undefined reference to `pcl::search::Search<pcl::PointXYZ>::nearestKSearch(pcl::PointCloud<pcl::PointXYZ> const&, std::vector<int, std::allocator<int> > const&, int, std::vector<std::vector<int, std::allocator<int> >, std::allocator<std::vector<int, std::allocator<int> > > >&, std::vector<std::vector<float, std::allocator<float> >, std::allocator<std::vector<float, std::allocator<float> > > >&) const'
/usr/bin/ld: CMakeFiles/Test.dir/main.cpp.o:(.data.rel.ro._ZTVN3pcl6search17OrganizedNeighborINS_8PointXYZEEE[_ZTVN3pcl6search17OrganizedNeighborINS_8PointXYZEEE]+0x70): undefined reference to `pcl::search::OrganizedNeighbor<pcl::PointXYZ>::radiusSearch(pcl::PointXYZ const&, double, std::vector<int, std::allocator<int> >&, std::vector<float, std::allocator<float> >&, unsigned int) const'
/usr/bin/ld: CMakeFiles/Test.dir/main.cpp.o:(.data.rel.ro._ZTVN3pcl6search17OrganizedNeighborINS_8PointXYZEEE[_ZTVN3pcl6search17OrganizedNeighborINS_8PointXYZEEE]+0x78): undefined reference to `pcl::search::Search<pcl::PointXYZ>::radiusSearch(pcl::PointCloud<pcl::PointXYZ> const&, int, double, std::vector<int, std::allocator<int> >&, std::vector<float, std::allocator<float> >&, unsigned int) const'
/usr/bin/ld: CMakeFiles/Test.dir/main.cpp.o:(.data.rel.ro._ZTVN3pcl6search17OrganizedNeighborINS_8PointXYZEEE[_ZTVN3pcl6search17OrganizedNeighborINS_8PointXYZEEE]+0x80): undefined reference to `pcl::search::Search<pcl::PointXYZ>::radiusSearch(int, double, std::vector<int, std::allocator<int> >&, std::vector<float, std::allocator<float> >&, unsigned int) const'
/usr/bin/ld: CMakeFiles/Test.dir/main.cpp.o:(.data.rel.ro._ZTVN3pcl6search17OrganizedNeighborINS_8PointXYZEEE[_ZTVN3pcl6search17OrganizedNeighborINS_8PointXYZEEE]+0x88): undefined reference to `pcl::search::Search<pcl::PointXYZ>::radiusSearch(pcl::PointCloud<pcl::PointXYZ> const&, std::vector<int, std::allocator<int> > const&, double, std::vector<std::vector<int, std::allocator<int> >, std::allocator<std::vector<int, std::allocator<int> > > >&, std::vector<std::vector<float, std::allocator<float> >, std::allocator<std::vector<float, std::allocator<float> > > >&, unsigned int) const'
/usr/bin/ld: CMakeFiles/Test.dir/main.cpp.o:(.data.rel.ro._ZTVN3pcl6search6KdTreeINS_8PointXYZENS_11KdTreeFLANNIS2_N5flann9L2_SimpleIfEEEEEE[_ZTVN3pcl6search6KdTreeINS_8PointXYZENS_11KdTreeFLANNIS2_N5flann9L2_SimpleIfEEEEEE]+0x20): undefined reference to `pcl::search::Search<pcl::PointXYZ>::getName[abi:cxx11]() const'
/usr/bin/ld: CMakeFiles/Test.dir/main.cpp.o:(.data.rel.ro._ZTVN3pcl6search6KdTreeINS_8PointXYZENS_11KdTreeFLANNIS2_N5flann9L2_SimpleIfEEEEEE[_ZTVN3pcl6search6KdTreeINS_8PointXYZENS_11KdTreeFLANNIS2_N5flann9L2_SimpleIfEEEEEE]+0x30): undefined reference to `pcl::search::Search<pcl::PointXYZ>::getSortedResults()'
/usr/bin/ld: CMakeFiles/Test.dir/main.cpp.o:(.data.rel.ro._ZTVN3pcl6search6KdTreeINS_8PointXYZENS_11KdTreeFLANNIS2_N5flann9L2_SimpleIfEEEEEE[_ZTVN3pcl6search6KdTreeINS_8PointXYZENS_11KdTreeFLANNIS2_N5flann9L2_SimpleIfEEEEEE]+0x58): undefined reference to `pcl::search::Search<pcl::PointXYZ>::nearestKSearch(pcl::PointCloud<pcl::PointXYZ> const&, int, int, std::vector<int, std::allocator<int> >&, std::vector<float, std::allocator<float> >&) const'
/usr/bin/ld: CMakeFiles/Test.dir/main.cpp.o:(.data.rel.ro._ZTVN3pcl6search6KdTreeINS_8PointXYZENS_11KdTreeFLANNIS2_N5flann9L2_SimpleIfEEEEEE[_ZTVN3pcl6search6KdTreeINS_8PointXYZENS_11KdTreeFLANNIS2_N5flann9L2_SimpleIfEEEEEE]+0x60): undefined reference to `pcl::search::Search<pcl::PointXYZ>::nearestKSearch(int, int, std::vector<int, std::allocator<int> >&, std::vector<float, std::allocator<float> >&) const'
/usr/bin/ld: CMakeFiles/Test.dir/main.cpp.o:(.data.rel.ro._ZTVN3pcl6search6KdTreeINS_8PointXYZENS_11KdTreeFLANNIS2_N5flann9L2_SimpleIfEEEEEE[_ZTVN3pcl6search6KdTreeINS_8PointXYZENS_11KdTreeFLANNIS2_N5flann9L2_SimpleIfEEEEEE]+0x68): undefined reference to `pcl::search::Search<pcl::PointXYZ>::nearestKSearch(pcl::PointCloud<pcl::PointXYZ> const&, std::vector<int, std::allocator<int> > const&, int, std::vector<std::vector<int, std::allocator<int> >, std::allocator<std::vector<int, std::allocator<int> > > >&, std::vector<std::vector<float, std::allocator<float> >, std::allocator<std::vector<float, std::allocator<float> > > >&) const'
/usr/bin/ld: CMakeFiles/Test.dir/main.cpp.o:(.data.rel.ro._ZTVN3pcl6search6KdTreeINS_8PointXYZENS_11KdTreeFLANNIS2_N5flann9L2_SimpleIfEEEEEE[_ZTVN3pcl6search6KdTreeINS_8PointXYZENS_11KdTreeFLANNIS2_N5flann9L2_SimpleIfEEEEEE]+0x78): undefined reference to `pcl::search::Search<pcl::PointXYZ>::radiusSearch(pcl::PointCloud<pcl::PointXYZ> const&, int, double, std::vector<int, std::allocator<int> >&, std::vector<float, std::allocator<float> >&, unsigned int) const'
/usr/bin/ld: CMakeFiles/Test.dir/main.cpp.o:(.data.rel.ro._ZTVN3pcl6search6KdTreeINS_8PointXYZENS_11KdTreeFLANNIS2_N5flann9L2_SimpleIfEEEEEE[_ZTVN3pcl6search6KdTreeINS_8PointXYZENS_11KdTreeFLANNIS2_N5flann9L2_SimpleIfEEEEEE]+0x80): undefined reference to `pcl::search::Search<pcl::PointXYZ>::radiusSearch(int, double, std::vector<int, std::allocator<int> >&, std::vector<float, std::allocator<float> >&, unsigned int) const'
/usr/bin/ld: CMakeFiles/Test.dir/main.cpp.o:(.data.rel.ro._ZTVN3pcl6search6KdTreeINS_8PointXYZENS_11KdTreeFLANNIS2_N5flann9L2_SimpleIfEEEEEE[_ZTVN3pcl6search6KdTreeINS_8PointXYZENS_11KdTreeFLANNIS2_N5flann9L2_SimpleIfEEEEEE]+0x88): undefined reference to `pcl::search::Search<pcl::PointXYZ>::radiusSearch(pcl::PointCloud<pcl::PointXYZ> const&, std::vector<int, std::allocator<int> > const&, double, std::vector<std::vector<int, std::allocator<int> >, std::allocator<std::vector<int, std::allocator<int> > > >&, std::vector<std::vector<float, std::allocator<float> >, std::allocator<std::vector<float, std::allocator<float> > > >&, unsigned int) const'
/usr/bin/ld: CMakeFiles/Test.dir/main.cpp.o:(.data.rel.ro._ZTVN3pcl6search6SearchINS_8PointXYZEEE[_ZTVN3pcl6search6SearchINS_8PointXYZEEE]+0x20): undefined reference to `pcl::search::Search<pcl::PointXYZ>::getName[abi:cxx11]() const'
/usr/bin/ld: CMakeFiles/Test.dir/main.cpp.o:(.data.rel.ro._ZTVN3pcl6search6SearchINS_8PointXYZEEE[_ZTVN3pcl6search6SearchINS_8PointXYZEEE]+0x28): undefined reference to `pcl::search::Search<pcl::PointXYZ>::setSortedResults(bool)'
/usr/bin/ld: CMakeFiles/Test.dir/main.cpp.o:(.data.rel.ro._ZTVN3pcl6search6SearchINS_8PointXYZEEE[_ZTVN3pcl6search6SearchINS_8PointXYZEEE]+0x30): undefined reference to `pcl::search::Search<pcl::PointXYZ>::getSortedResults()'
/usr/bin/ld: CMakeFiles/Test.dir/main.cpp.o:(.data.rel.ro._ZTVN3pcl6search6SearchINS_8PointXYZEEE[_ZTVN3pcl6search6SearchINS_8PointXYZEEE]+0x38): undefined reference to `pcl::search::Search<pcl::PointXYZ>::setInputCloud(std::shared_ptr<pcl::PointCloud<pcl::PointXYZ> const> const&, std::shared_ptr<std::vector<int, std::allocator<int> > const> const&)'
/usr/bin/ld: CMakeFiles/Test.dir/main.cpp.o:(.data.rel.ro._ZTVN3pcl6search6SearchINS_8PointXYZEEE[_ZTVN3pcl6search6SearchINS_8PointXYZEEE]+0x58): undefined reference to `pcl::search::Search<pcl::PointXYZ>::nearestKSearch(pcl::PointCloud<pcl::PointXYZ> const&, int, int, std::vector<int, std::allocator<int> >&, std::vector<float, std::allocator<float> >&) const'
/usr/bin/ld: CMakeFiles/Test.dir/main.cpp.o:(.data.rel.ro._ZTVN3pcl6search6SearchINS_8PointXYZEEE[_ZTVN3pcl6search6SearchINS_8PointXYZEEE]+0x60): undefined reference to `pcl::search::Search<pcl::PointXYZ>::nearestKSearch(int, int, std::vector<int, std::allocator<int> >&, std::vector<float, std::allocator<float> >&) const'
/usr/bin/ld: CMakeFiles/Test.dir/main.cpp.o:(.data.rel.ro._ZTVN3pcl6search6SearchINS_8PointXYZEEE[_ZTVN3pcl6search6SearchINS_8PointXYZEEE]+0x68): undefined reference to `pcl::search::Search<pcl::PointXYZ>::nearestKSearch(pcl::PointCloud<pcl::PointXYZ> const&, std::vector<int, std::allocator<int> > const&, int, std::vector<std::vector<int, std::allocator<int> >, std::allocator<std::vector<int, std::allocator<int> > > >&, std::vector<std::vector<float, std::allocator<float> >, std::allocator<std::vector<float, std::allocator<float> > > >&) const'
/usr/bin/ld: CMakeFiles/Test.dir/main.cpp.o:(.data.rel.ro._ZTVN3pcl6search6SearchINS_8PointXYZEEE[_ZTVN3pcl6search6SearchINS_8PointXYZEEE]+0x78): undefined reference to `pcl::search::Search<pcl::PointXYZ>::radiusSearch(pcl::PointCloud<pcl::PointXYZ> const&, int, double, std::vector<int, std::allocator<int> >&, std::vector<float, std::allocator<float> >&, unsigned int) const'
/usr/bin/ld: CMakeFiles/Test.dir/main.cpp.o:(.data.rel.ro._ZTVN3pcl6search6SearchINS_8PointXYZEEE[_ZTVN3pcl6search6SearchINS_8PointXYZEEE]+0x80): undefined reference to `pcl::search::Search<pcl::PointXYZ>::radiusSearch(int, double, std::vector<int, std::allocator<int> >&, std::vector<float, std::allocator<float> >&, unsigned int) const'
/usr/bin/ld: CMakeFiles/Test.dir/main.cpp.o:(.data.rel.ro._ZTVN3pcl6search6SearchINS_8PointXYZEEE[_ZTVN3pcl6search6SearchINS_8PointXYZEEE]+0x88): undefined reference to `pcl::search::Search<pcl::PointXYZ>::radiusSearch(pcl::PointCloud<pcl::PointXYZ> const&, std::vector<int, std::allocator<int> > const&, double, std::vector<std::vector<int, std::allocator<int> >, std::allocator<std::vector<int, std::allocator<int> > > >&, std::vector<std::vector<float, std::allocator<float> >, std::allocator<std::vector<float, std::allocator<float> > > >&, unsigned int) const'
/usr/bin/ld: CMakeFiles/Test.dir/main.cpp.o: in function `pcl::search::OrganizedNeighbor<pcl::PointXYZ>::setInputCloud(std::shared_ptr<pcl::PointCloud<pcl::PointXYZ> const> const&, std::shared_ptr<std::vector<int, std::allocator<int> > const> const&)':
main.cpp:(.text._ZN3pcl6search17OrganizedNeighborINS_8PointXYZEE13setInputCloudERKSt10shared_ptrIKNS_10PointCloudIS2_EEERKS4_IKSt6vectorIiSaIiEEE[_ZN3pcl6search17OrganizedNeighborINS_8PointXYZEE13setInputCloudERKSt10shared_ptrIKNS_10PointCloudIS2_EEERKS4_IKSt6vectorIiSaIiEEE]+0x1ea): undefined reference to `pcl::search::OrganizedNeighbor<pcl::PointXYZ>::estimateProjectionMatrix()'
collect2: error: ld returned 1 exit status
make[2]: *** [CMakeFiles/Test.dir/build.make:154: Test] Error 1
make[1]: *** [CMakeFiles/Makefile2:83: CMakeFiles/Test.dir/all] Error 2
make: *** [Makefile:91: all] Error 2
我发现了一些人们遇到的与此类似的相关问题,并且我已经尝试了提供的所有解决方案而没有任何帮助。
我正在 Arch linux 1.4、PCL 版本 1.12.1 上构建这个
编辑:以下是
make -j6 VERBOSE=1
的输出
❯ make -j6 VERBOSE=1
/usr/local/bin/cmake -S/home/beany/Documents/projects/pc2mesh -B/home/beany/Documents/projects/pc2mesh/build --check-build-system CMakeFiles/Makefile.cmake 0
/usr/local/bin/cmake -E cmake_progress_start /home/beany/Documents/projects/pc2mesh/build/CMakeFiles /home/beany/Documents/projects/pc2mesh/build//CMakeFiles/progress.marks
make -f CMakeFiles/Makefile2 all
make[1]: Entering directory '/home/beany/Documents/projects/pc2mesh/build'
make -f CMakeFiles/Test.dir/build.make CMakeFiles/Test.dir/depend
make[2]: Entering directory '/home/beany/Documents/projects/pc2mesh/build'
cd /home/beany/Documents/projects/pc2mesh/build && /usr/local/bin/cmake -E cmake_depends "Unix Makefiles" /home/beany/Documents/projects/pc2mesh /home/beany/Documents/projects/pc2mesh /home/beany/Documents/projects/pc2mesh/build /home/beany/Documents/projects/pc2mesh/build /home/beany/Documents/projects/pc2mesh/build/CMakeFiles/Test.dir/DependInfo.cmake --color=
make[2]: Leaving directory '/home/beany/Documents/projects/pc2mesh/build'
make -f CMakeFiles/Test.dir/build.make CMakeFiles/Test.dir/build
make[2]: Entering directory '/home/beany/Documents/projects/pc2mesh/build'
[ 50%] Building CXX object CMakeFiles/Test.dir/main.cpp.o
/opt/cuda/bin/g++ -DBOOST_ATOMIC_DYN_LINK -DBOOST_ATOMIC_NO_LIB -DBOOST_DATE_TIME_DYN_LINK -DBOOST_DATE_TIME_NO_LIB -DBOOST_FILESYSTEM_DYN_LINK -DBOOST_FILESYSTEM_NO_LIB -DBOOST_IOSTREAMS_DYN_LINK -DBOOST_IOSTREAMS_NO_LIB -DBOOST_SERIALIZATION_DYN_LINK -DBOOST_SERIALIZATION_NO_LIB -DBOOST_SYSTEM_DYN_LINK -DBOOST_SYSTEM_NO_LIB -DDISABLE_PCAP -DDISABLE_PNG -DQT_CORE_LIB -DQT_GUI_LIB -DQT_NO_DEBUG -DQT_OPENGL_LIB -DQT_WIDGETS_LIB -Dkiss_fft_scalar=double -isystem /usr/include/pcl-1.12 -isystem /usr/include/eigen3 -isystem /usr/include/ni -isystem /usr/include/openni2 -isystem /usr/include/vtk -isystem /usr/include/freetype2 -isystem /usr/include/qt -isystem /usr/include/qt/QtOpenGL -isystem /usr/include/qt/QtWidgets -isystem /usr/include/qt/QtGui -isystem /usr/include/qt/QtCore -isystem /usr/lib/qt/mkspecs/linux-g++ -msse4.2 -mfpmath=sse -march=native -mavx2 -pthread -fopenmp -fPIC -MD -MT CMakeFiles/Test.dir/main.cpp.o -MF CMakeFiles/Test.dir/main.cpp.o.d -o CMakeFiles/Test.dir/main.cpp.o -c /home/beany/Documents/projects/pc2mesh/main.cpp
[100%] Linking CXX executable Test
/usr/local/bin/cmake -E cmake_link_script CMakeFiles/Test.dir/link.txt --verbose=1
/opt/cuda/bin/g++ -rdynamic CMakeFiles/Test.dir/main.cpp.o -o Test -Wl,-rpath,/usr/lib/openmpi /usr/lib/libpcl_io.so -lOpenNI /usr/lib/libusb-1.0.so -lOpenNI2 /usr/lib/libusb-1.0.so /usr/lib/libvtkChartsCore.so.9.1.0 /usr/lib/libvtkInteractionImage.so.9.1.0 /usr/lib/libvtkIOGeometry.so.9.1.0 /usr/lib/libvtkIOPLY.so.9.1.0 /usr/lib/libvtkRenderingLOD.so.9.1.0 /usr/lib/libvtkViewsContext2D.so.9.1.0 /usr/lib/libvtkGUISupportQt.so.9.1.0 -llz4 -lpthread /usr/lib/libpcl_octree.so /usr/lib/libpcl_common.so /usr/lib/libboost_system.so.1.78.0 /usr/lib/libboost_filesystem.so.1.78.0 /usr/lib/libboost_atomic.so.1.78.0 /usr/lib/libboost_date_time.so.1.78.0 /usr/lib/libboost_iostreams.so.1.78.0 /usr/lib/libboost_serialization.so.1.78.0 /usr/lib/libjsoncpp.so /usr/lib/libvtkViewsCore.so.9.1.0 /usr/lib/libvtkInteractionWidgets.so.9.1.0 /usr/lib/libvtkFiltersModeling.so.9.1.0 /usr/lib/libvtkInteractionStyle.so.9.1.0 /usr/lib/libvtkFiltersExtraction.so.9.1.0 /usr/lib/libvtkIOLegacy.so.9.1.0 /usr/lib/libvtkIOCore.so.9.1.0 /usr/lib/libvtkRenderingAnnotation.so.9.1.0 /usr/lib/libvtkRenderingContext2D.so.9.1.0 /usr/lib/libvtkRenderingFreeType.so.9.1.0 /usr/lib/libfreetype.so /usr/lib/libvtkImagingSources.so.9.1.0 /usr/lib/libvtkIOImage.so.9.1.0 /usr/lib/libvtkImagingCore.so.9.1.0 /usr/lib/libvtkRenderingOpenGL2.so.9.1.0 /usr/lib/libvtkRenderingUI.so.9.1.0 /usr/lib/libvtkRenderingCore.so.9.1.0 /usr/lib/libvtkCommonColor.so.9.1.0 /usr/lib/libvtkFiltersGeometry.so.9.1.0 /usr/lib/libvtkFiltersSources.so.9.1.0 /usr/lib/libvtkFiltersGeneral.so.9.1.0 /usr/lib/libvtkCommonComputationalGeometry.so.9.1.0 /usr/lib/libvtkFiltersCore.so.9.1.0 /usr/lib/libvtkCommonExecutionModel.so.9.1.0 /usr/lib/libvtkCommonDataModel.so.9.1.0 /usr/lib/libvtkCommonMisc.so.9.1.0 /usr/lib/libvtkCommonTransforms.so.9.1.0 /usr/lib/libvtkCommonMath.so.9.1.0 /usr/lib/libvtkkissfft.so.9.1.0 /usr/lib/libGLEW.so /usr/lib/libX11.so /usr/lib/libQt5OpenGL.so.5.15.2 /usr/lib/libQt5Widgets.so.5.15.2 /usr/lib/libQt5Gui.so.5.15.2 /usr/lib/libQt5Core.so.5.15.2 /usr/lib/libvtkCommonCore.so.9.1.0 -pthread /usr/lib/libtbb.so.12.5 -lgomp -lpthread /usr/lib/libvtksys.so.9.1.0 -ldl -Wl,-rpath-link,/usr/lib/openmpi
我刚刚在https://pcl.readthedocs.io/projects/tutorials/en/master/greedy_projection.html#greedy-triangulation中获得了代码,我复制并粘贴了代码.cpp和解释的CMakeList.txt该教程对我来说效果很好。
查看代码中的差异,我发现当我在 find_package 中没有“common io”的情况下编译时,它的编译没有问题。我正在使用 PCL 1.2 和 ubuntu 20.04。
就我而言,CMakeList 中的更改如下: find_package(PCL 1.2 所需组件)
@Junior 上面发布的答案也解决了我的问题。只需从 find_package 中删除“common io”即可。参考https://github.com/PointCloudLibrary/pcl/tree/master/doc/tutorials/content/sources/greedy_projection。
工作中的CMakeList.txt
cmake_minimum_required(VERSION 3.5 FATAL_ERROR)
project(TestProject)
find_package(PCL 1.2 REQUIRED)
include_directories(${PCL_INCLUDE_DIRS})
link_directories(${PCL_LIBRARY_DIRS})
add_definitions(${PCL_DEFINITIONS})
add_executable (Test main.cpp)
target_link_libraries (Test ${PCL_LIBRARIES})
编译CMakeList.txt失败
cmake_minimum_required(VERSION 3.5 FATAL_ERROR)
project(TestProject)
find_package(PCL 1.2 REQUIRED common io)
include_directories(${PCL_INCLUDE_DIRS})
link_directories(${PCL_LIBRARY_DIRS})
add_definitions(${PCL_DEFINITIONS})
add_executable (Test main.cpp)
target_link_libraries (Test ${PCL_LIBRARIES})
如果一切都失败,请重新安装它https://github.com/PointCloudLibrary/pcl/issues/4790#issuecomment-855379558
卸载
sudo apt-get purge --auto-remove libpcl-dev
重新安装
sudo apt install libpcl-dev
将
search
模块添加到 find_package
中所需组件的列表中应该可以解决链接错误。毕竟,您正在使用该模块中的类。