踩坑記錄:windows11下使用 VS2022 和 PCL1.14.1 配置點雲開發環境

kyszd發表於2024-07-22

閒話不多說,具體在windows下下載PCL與解壓pcl可以看https://www.yuque.com/huangzhongqing/pcl/這位大佬的文章,那我就具體說一下踩過點坑:

踩坑點1:

按照大佬的文章的步驟進行解壓與下載,我的PCL環境下在了K盤中,但是最後不知怎麼的我的openni2資料夾下在了C盤裡,也就是說3rdparty資料夾下的openni2沒有下一層目錄了,我的做法就是把c盤裡openni2目錄下的檔案都複製到了K盤中。當然也可以不復制,在配置環境變數時記得要寫c盤的openni2不要寫K盤的就可以。

踩坑點2:

安裝PCL時,如果選擇新增環境變數可能會出現“環境變數長度超過1023”這樣類似的錯誤,這時候需要手動配置一下,下面是我的配置辦法:


在這張圖中,這三個變數應該是安裝的時候可以自動寫到環境變數裡的,第三行是我手動修改了,放到了k盤裡,其實可以不放,只要記得是C盤就行,前兩行也同樣。還有就是下圖這個

也是可以自動填寫上的,需要我們手動新增的是下面這些:


我們在Path裡,尾部加上這些就可以了。

踩坑點3:

連結庫問題,這也是比較棘手的問題之一,在3rdparty下的每一個資料夾下的lib資料夾中,新建一個txt檔案,內容填寫:DIR *.lib /B >liblist.txt DIR .lib /B:列出當前目錄中所有以 .lib 為副檔名的檔案,且使用簡潔的輸出格式。DIR:顯示目錄中的檔案和子目錄列表。*.lib:匹配所有以 .lib 結尾的檔案。/B:使用簡潔格式輸出,只顯示檔名,不顯示日期、時間、檔案大小等詳細資訊。liblist.txt是你需要重定向的檔名。最後再把寫入命令的txt字尾修改為bat,雙擊執行即可吧lib檔名稱全部寫入到liblist.txt中。完成上述操作後,當我們執行時,可能會出現下圖的錯誤:

這個錯誤的排除也是耗費了我很長時間,最後找到了原因:上面我們得到的liblist列表中,同時包括debug和release版本的lib,那麼vs執行的時候就會產生衝突,從而報錯,具體做法是我們可以去掉非debug版本的lib檔案,比如你把“pcl_registrationd.lib”和 “pcl_registration.lib” 都寫上去了那麼就去掉後面不帶d的,前面有“gd”字尾的一樣,保留它,去掉不帶gd的。下面是1.14.1我整理好的庫:

libboost_atomic-vc143-mt-gd-x64-1_84.lib
libboost_bzip2-vc143-mt-gd-x64-1_84.lib
libboost_chrono-vc143-mt-gd-x64-1_84.lib
libboost_container-vc143-mt-gd-x64-1_84.lib
libboost_context-vc143-mt-gd-x64-1_84.lib
libboost_contract-vc143-mt-gd-x64-1_84.lib
libboost_coroutine-vc143-mt-gd-x64-1_84.lib
libboost_date_time-vc143-mt-gd-x64-1_84.lib
libboost_exception-vc143-mt-gd-x64-1_84.lib
libboost_fiber-vc143-mt-gd-x64-1_84.lib
libboost_filesystem-vc143-mt-gd-x64-1_84.lib
libboost_graph-vc143-mt-gd-x64-1_84.lib
libboost_graph_parallel-vc143-mt-gd-x64-1_84.lib
libboost_iostreams-vc143-mt-gd-x64-1_84.lib
libboost_json-vc143-mt-gd-x64-1_84.lib
libboost_locale-vc143-mt-gd-x64-1_84.lib
libboost_log-vc143-mt-gd-x64-1_84.lib
libboost_log_setup-vc143-mt-gd-x64-1_84.lib
libboost_math_c99-vc143-mt-gd-x64-1_84.lib
libboost_math_c99f-vc143-mt-gd-x64-1_84.lib
libboost_math_c99l-vc143-mt-gd-x64-1_84.lib
libboost_math_tr1-vc143-mt-gd-x64-1_84.lib
libboost_math_tr1f-vc143-mt-gd-x64-1_84.lib
libboost_math_tr1l-vc143-mt-gd-x64-1_84.lib
libboost_mpi-vc143-mt-gd-x64-1_84.lib
libboost_nowide-vc143-mt-gd-x64-1_84.lib
libboost_numpy310-vc143-mt-gd-x64-1_84.lib
libboost_prg_exec_monitor-vc143-mt-gd-x64-1_84.lib
libboost_program_options-vc143-mt-gd-x64-1_84.lib
libboost_python310-vc143-mt-gd-x64-1_84.lib
libboost_random-vc143-mt-gd-x64-1_84.lib
libboost_regex-vc143-mt-gd-x64-1_84.lib
libboost_serialization-vc143-mt-gd-x64-1_84.lib
libboost_stacktrace_noop-vc143-mt-gd-x64-1_84.lib
libboost_stacktrace_windbg-vc143-mt-gd-x64-1_84.lib
libboost_stacktrace_windbg_cached-vc143-mt-gd-x64-1_84.lib
libboost_system-vc143-mt-gd-x64-1_84.lib
libboost_test_exec_monitor-vc143-mt-gd-x64-1_84.lib
libboost_thread-vc143-mt-gd-x64-1_84.lib
libboost_timer-vc143-mt-gd-x64-1_84.lib
libboost_type_erasure-vc143-mt-gd-x64-1_84.lib
libboost_unit_test_framework-vc143-mt-gd-x64-1_84.lib
libboost_url-vc143-mt-gd-x64-1_84.lib
libboost_wave-vc143-mt-gd-x64-1_84.lib
libboost_wserialization-vc143-mt-gd-x64-1_84.lib
libboost_zlib-vc143-mt-gd-x64-1_84.lib
flann-gd.lib
flann_cpp-gd.lib
flann_cpp_s-gd.lib
flann_s-gd.lib
qhullcpp.lib
qhullcpp_d.lib
qhullstatic.lib
qhullstatic_d.lib
qhullstatic_rd.lib
qhull_rd.lib
vtkcgns-9.3-gd.lib
vtkChartsCore-9.3-gd.lib
vtkCommonColor-9.3-gd.lib
vtkCommonComputationalGeometry-9.3-gd.lib
vtkCommonCore-9.3-gd.lib
vtkCommonDataModel-9.3-gd.lib
vtkCommonExecutionModel-9.3-gd.lib
vtkCommonMath-9.3-gd.lib
vtkCommonMisc-9.3-gd.lib
vtkCommonSystem-9.3-gd.lib
vtkCommonTransforms-9.3-gd.lib
vtkDICOMParser-9.3-gd.lib
vtkDomainsChemistry-9.3-gd.lib
vtkDomainsChemistryOpenGL2-9.3-gd.lib
vtkdoubleconversion-9.3-gd.lib
vtkexodusII-9.3-gd.lib
vtkexpat-9.3-gd.lib
vtkFiltersAMR-9.3-gd.lib
vtkFiltersCellGrid-9.3-gd.lib
vtkFiltersCore-9.3-gd.lib
vtkFiltersExtraction-9.3-gd.lib
vtkFiltersFlowPaths-9.3-gd.lib
vtkFiltersGeneral-9.3-gd.lib
vtkFiltersGeneric-9.3-gd.lib
vtkFiltersGeometry-9.3-gd.lib
vtkFiltersGeometryPreview-9.3-gd.lib
vtkFiltersHybrid-9.3-gd.lib
vtkFiltersHyperTree-9.3-gd.lib
vtkFiltersImaging-9.3-gd.lib
vtkFiltersModeling-9.3-gd.lib
vtkFiltersParallel-9.3-gd.lib
vtkFiltersParallelImaging-9.3-gd.lib
vtkFiltersPoints-9.3-gd.lib
vtkFiltersProgrammable-9.3-gd.lib
vtkFiltersReduction-9.3-gd.lib
vtkFiltersSelection-9.3-gd.lib
vtkFiltersSMP-9.3-gd.lib
vtkFiltersSources-9.3-gd.lib
vtkFiltersStatistics-9.3-gd.lib
vtkFiltersTensor-9.3-gd.lib
vtkFiltersTexture-9.3-gd.lib
vtkFiltersTopology-9.3-gd.lib
vtkFiltersVerdict-9.3-gd.lib
vtkfmt-9.3-gd.lib
vtkfreetype-9.3-gd.lib
vtkGeovisCore-9.3-gd.lib
vtkgl2ps-9.3-gd.lib
vtkglew-9.3-gd.lib
vtkhdf5-9.3-gd.lib
vtkhdf5_hl-9.3-gd.lib
vtkImagingColor-9.3-gd.lib
vtkImagingCore-9.3-gd.lib
vtkImagingFourier-9.3-gd.lib
vtkImagingGeneral-9.3-gd.lib
vtkImagingHybrid-9.3-gd.lib
vtkImagingMath-9.3-gd.lib
vtkImagingMorphological-9.3-gd.lib
vtkImagingSources-9.3-gd.lib
vtkImagingStatistics-9.3-gd.lib
vtkImagingStencil-9.3-gd.lib
vtkInfovisCore-9.3-gd.lib
vtkInfovisLayout-9.3-gd.lib
vtkInteractionImage-9.3-gd.lib
vtkInteractionStyle-9.3-gd.lib
vtkInteractionWidgets-9.3-gd.lib
vtkIOAMR-9.3-gd.lib
vtkIOAsynchronous-9.3-gd.lib
vtkIOCellGrid-9.3-gd.lib
vtkIOCesium3DTiles-9.3-gd.lib
vtkIOCGNSReader-9.3-gd.lib
vtkIOChemistry-9.3-gd.lib
vtkIOCityGML-9.3-gd.lib
vtkIOCONVERGECFD-9.3-gd.lib
vtkIOCore-9.3-gd.lib
vtkIOEnSight-9.3-gd.lib
vtkIOExodus-9.3-gd.lib
vtkIOExport-9.3-gd.lib
vtkIOExportGL2PS-9.3-gd.lib
vtkIOExportPDF-9.3-gd.lib
vtkIOFLUENTCFF-9.3-gd.lib
vtkIOGeometry-9.3-gd.lib
vtkIOHDF-9.3-gd.lib
vtkIOImage-9.3-gd.lib
vtkIOImport-9.3-gd.lib
vtkIOInfovis-9.3-gd.lib
vtkIOIOSS-9.3-gd.lib
vtkIOLegacy-9.3-gd.lib
vtkIOLSDyna-9.3-gd.lib
vtkIOMINC-9.3-gd.lib
vtkIOMotionFX-9.3-gd.lib
vtkIOMovie-9.3-gd.lib
vtkIONetCDF-9.3-gd.lib
vtkIOOggTheora-9.3-gd.lib
vtkIOParallel-9.3-gd.lib
vtkIOParallelXML-9.3-gd.lib
vtkIOPLY-9.3-gd.lib
vtkIOSegY-9.3-gd.lib
vtkIOSQL-9.3-gd.lib
vtkioss-9.3-gd.lib
vtkIOTecplotTable-9.3-gd.lib
vtkIOVeraOut-9.3-gd.lib
vtkIOVideo-9.3-gd.lib
vtkIOXML-9.3-gd.lib
vtkIOXMLParser-9.3-gd.lib
vtkjpeg-9.3-gd.lib
vtkjsoncpp-9.3-gd.lib
vtkkissfft-9.3-gd.lib
vtklibharu-9.3-gd.lib
vtklibproj-9.3-gd.lib
vtklibxml2-9.3-gd.lib
vtkloguru-9.3-gd.lib
vtklz4-9.3-gd.lib
vtklzma-9.3-gd.lib
vtkmetaio-9.3-gd.lib
vtknetcdf-9.3-gd.lib
vtkogg-9.3-gd.lib
vtkParallelCore-9.3-gd.lib
vtkParallelDIY-9.3-gd.lib
vtkpng-9.3-gd.lib
vtkpugixml-9.3-gd.lib
vtkRenderingAnnotation-9.3-gd.lib
vtkRenderingCellGrid-9.3-gd.lib
vtkRenderingContext2D-9.3-gd.lib
vtkRenderingContextOpenGL2-9.3-gd.lib
vtkRenderingCore-9.3-gd.lib
vtkRenderingFreeType-9.3-gd.lib
vtkRenderingGL2PSOpenGL2-9.3-gd.lib
vtkRenderingHyperTreeGrid-9.3-gd.lib
vtkRenderingImage-9.3-gd.lib
vtkRenderingLabel-9.3-gd.lib
vtkRenderingLICOpenGL2-9.3-gd.lib
vtkRenderingLOD-9.3-gd.lib
vtkRenderingOpenGL2-9.3-gd.lib
vtkRenderingSceneGraph-9.3-gd.lib
vtkRenderingUI-9.3-gd.lib
vtkRenderingVolume-9.3-gd.lib
vtkRenderingVolumeOpenGL2-9.3-gd.lib
vtkRenderingVtkJS-9.3-gd.lib
vtksqlite-9.3-gd.lib
vtksys-9.3-gd.lib
vtkTestingRendering-9.3-gd.lib
vtktheora-9.3-gd.lib
vtktiff-9.3-gd.lib
vtkverdict-9.3-gd.lib
vtkViewsContext2D-9.3-gd.lib
vtkViewsCore-9.3-gd.lib
vtkViewsInfovis-9.3-gd.lib
vtkWrappingTools-9.3-gd.lib
vtkzlib-9.3-gd.lib
pcl_commond.lib
pcl_featuresd.lib
pcl_filtersd.lib
pcl_iod.lib
pcl_io_plyd.lib
pcl_kdtreed.lib
pcl_keypointsd.lib
pcl_mld.lib
pcl_octreed.lib
pcl_outofcored.lib
pcl_peopled.lib
pcl_recognitiond.lib
pcl_registrationd.lib
pcl_sample_consensusd.lib
pcl_searchd.lib
pcl_segmentationd.lib
pcl_stereod.lib
pcl_surfaced.lib
pcl_trackingd.lib
pcl_visualizationd.lib

上面這個問題,同樣適用於執行結果不報錯,但是卻在console視窗顯示非0退出的語句這個問題。

踩坑點4:

無法解析的外部符號 "void __cdecl vtkRenderingOpenGL_AutoInit_Construct(void)" (?vtkRenderingOpenGL_AutoInit_Construct@@YAXXZ),函式 "public: __cdecl `anonymous namespace'::vtkRenderingOpenGL_ModuleInit::vtkRenderingOpenGL_ModuleInit(void)" (??0vtkRenderingOpenGL_ModuleInit@?A0xdbae2661@@QEAA@XZ)
我用的是文章開頭大佬的文章中的程式碼:

#include <pcl/visualization/cloud_viewer.h>
#include <iostream>
#include <pcl/io/io.h>
#include <pcl/io/pcd_io.h>
#include <vtkAutoInit.h>
VTK_MODULE_INIT(vtkInteractionStyle);
VTK_MODULE_INIT(vtkRenderingFreeType);
VTK_MODULE_INIT(vtkRenderingOpenGL);
 
int user_data;
 
void viewerOneOff(pcl::visualization::PCLVisualizer& viewer)
{
    viewer.setBackgroundColor(1.0, 0.5, 1.0);
    pcl::PointXYZ o;
    o.x = 1.0;
    o.y = 0;
    o.z = 0;
    viewer.addSphere(o, 0.25, "sphere", 0);
    std::cout << "i only run once" << std::endl;
 
}
 
void viewerPsycho(pcl::visualization::PCLVisualizer& viewer)
{
    static unsigned count = 0;
    std::stringstream ss;
    ss << "Once per viewer loop: " << count++;
    viewer.removeShape("text", 0);
    viewer.addText(ss.str(), 200, 300, "text", 0);
 
    //FIXME: possible race condition here:
    user_data++;
}
 
int main()
{
    pcl::PointCloud<pcl::PointXYZRGBA>::Ptr cloud(new pcl::PointCloud<pcl::PointXYZRGBA>);
    pcl::io::loadPCDFile("rabbit.pcd", *cloud);
 
    pcl::visualization::CloudViewer viewer("Cloud Viewer");
 
 
 
    //blocks until the cloud is actually rendered
    viewer.showCloud(cloud);
 
    //use the following functions to get access to the underlying more advanced/powerful
    //PCLVisualizer
 
    //This will only get called once
    viewer.runOnVisualizationThreadOnce(viewerOneOff);
 
    //This will get called once per visualization iteration
    viewer.runOnVisualizationThread(viewerPsycho);
    while (!viewer.wasStopped())
    {
        //you can also do cool processing here
        //FIXME: Note that this is running in a separate thread from viewerPsycho
        //and you should guard against race conditions yourself...
        user_data++;
    }
    return 0;
}

只需要把VTK_MODULE_INIT(vtkRenderingOpenGL);改為VTK_MODULE_INIT(vtkRenderingOpenGL2);即可

相關文章