C++
相关工具使用
CMake——自动构建项目的工具
1 2 3 4 5 6 7 8 9 10 11 12 13 14
| cmake_minimum_required(VERSION 3.10)
project(Rasterizer)
find_package(OpenCV REQUIRED)
set(CMAKE_CXX_STANDARD 17)
include_directories(/usr/local/include)
add_executable(Rasterizer main.cpp rasterizer.hpp rasterizer.cpp Triangle.hpp Triangle.cpp)
target_link_libraries(Rasterizer ${OpenCV_LIBRARIES})
|
配置CGAL库
一、安装 Boost
1. 下载 Boost
从 Boost C++ Libraries - SourceForge 下载合适版本。根据 Visual Studio 版本选择相应的 Boost 版本:
- VC2015 对应 14.0
- VC2017 对应 14.1
- VC2019 对应 14.2
例如,下载 boost_1_76_0-msvc-14.2-64.exe
。
2. 安装 Boost
运行下载的 boost_1_76_0-msvc-14.2-64.exe
文件,将 Boost 安装到指定目录,例如:D:\dev\boost_1_76_0
。
3. 配置环境变量
- 设置 Boost 的库目录和包含目录:
- 打开系统环境变量设置:
我的电脑
-> 属性
-> 高级系统设置
-> 环境变量
- 新建或编辑以下环境变量:
BOOST_LIBRARYDIR = D:\dev\boost_1_76_0\lib64-msvc-14.2
BOOST_INCLUDEDIR = D:\dev\boost_1_76_0
- 将 Boost 的库路径添加到系统环境变量
PATH
中:
- 在系统环境变量
PATH
中,添加 D:\dev\boost_1_76_0\lib64-msvc-14.2
二、下载并安装 CGAL
1. 下载 CGAL
从 CGAL GitHub Releases 页面下载 CGAL 安装程序,例如 CGAL-5.0.2-Setup.exe
。
2. 安装 CGAL
运行下载的 CGAL-5.0.2-Setup.exe
文件,按照安装向导完成安装。
3. 配置环境变量
安装完成后,将 CGAL 的 GMP 库路径添加到系统环境变量 PATH
中:
- 打开系统环境变量设置:
我的电脑
-> 属性
-> 高级系统设置
-> 环境变量
- 在系统环境变量
PATH
中,添加 D:\dev\CGAL-5.0.2\auxiliary\gmp\lib
三、配置VS2019属性页
1. 连接器 - 输入 - 附加依赖项
在 Visual Studio 中,配置项目属性页,添加以下附加依赖项:
1 2
| D:\dev\CGAL-5.0.2\auxiliary\gmp\lib\libmpfr-4.lib D:\dev\CGAL-5.0.2\auxiliary\gmp\lib\libgmp-10.lib
|
2. C/C++ - 常规 - 附加包含目录
在 Visual Studio 中,配置项目属性页,添加以下附加包含目录:
1 2 3
| D:\dev\CGAL-5.0.2\auxiliary\gmp\include D:\boost_1_76_0 D:\dev\CGAL-5.0.2\include
|
3. 测试代码
编写并运行以下测试代码,以确保配置正确并验证依赖项和包含目录的有效性。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32
| #include <iostream> #include <CGAL/Simple_cartesian.h> typedef CGAL::Simple_cartesian<double> Kernel; typedef Kernel::Point_2 Point_2; typedef Kernel::Segment_2 Segment_2; int main() { Point_2 p(1, 1), q(10, 10); std::cout << "p = " << p << std::endl; std::cout << "q = " << q.x() << " " << q.y() << std::endl; std::cout << "sqdist(p,q) = " << CGAL::squared_distance(p, q) << std::endl; Segment_2 s(p, q); Point_2 m(5, 9); std::cout << "m = " << m << std::endl; std::cout << "sqdist(Segment_2(p,q), m) = " << CGAL::squared_distance(s, m) << std::endl; std::cout << "p, q, and m "; switch (CGAL::orientation(p, q, m)) { case CGAL::COLLINEAR: std::cout << "are collinear\n"; break; case CGAL::LEFT_TURN: std::cout << "make a left turn\n"; break; case CGAL::RIGHT_TURN: std::cout << "make a right turn\n"; break; } std::cout << " midpoint(p,q) = " << CGAL::midpoint(p, q) << std::endl; return 0; }
|
配置PCL库
配置属性-调试-环境-添加:
1
| PATH=D:\PCL 1.11.1\\bin;D:\PCL 1.11.1\\3rdParty\FLANN\bin;D:\PCL 1.11.1\\3rdParty\VTK\bin;D:\PCL 1.11.1\\3rdParty\OpenNI2\Tools
|
C/C++-常规-SDL检查:否
C/C++-语言-符合模式:否
VC++目录一包含目录,添加7个include路径
1 2 3 4 5 6 7
| D:\PCL 1.11.1\include\pcl-1.11 D:\PCL 1.11.1\3rdParty\Boost\include\boost-1_74 D:\PCL 1.11.1\3rdParty\Eigen\eigen3 D:\PCL 1.11.1\3rdParty\FLANN\include D:\PCL 1.11.1\3rdParty\OpenNI2\Include D:\PCL 1.11.1\3rdParty\Qhull\include D:\PCL 1.11.1\3rdParty\VTK\include\vtk-8.2
|
VC++目录一库目录,添加6个ib路径
1 2 3 4 5 6
| D:\PCL 1.11.1\lib D:\PCL 1.11.1\3rdParty\Boost\lib D:\PCL 1.11.1\3rdParty\FLANN\lib D:\PCL 1.11.1\3rdParty\OpenNI2\Lib D:\PCL 1.11.1\3rdParty\Qhull\lib D:\PCL 1.11.1\3rdParty\VTK\lib
|
C/C++-预处理器-预处理器定义-添加:
1 2 3
| BOOST_USE_WINDOWS_H NOMINMAX _CRT_SECURE_NO_DEPRECATE
|
链接器一输入一附加依赖项—添加PCL和VTK的相关lib文件
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143
| 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 vtkChartsCore-8.2-gd.lib vtkCommonColor-8.2-gd.lib vtkCommonComputationalGeometry-8.2-gd.lib vtkCommonCore-8.2-gd.lib vtkCommonDataModel-8.2-gd.lib vtkCommonExecutionModel-8.2-gd.lib vtkCommonMath-8.2-gd.lib vtkCommonMisc-8.2-gd.lib vtkCommonSystem-8.2-gd.lib vtkCommonTransforms-8.2-gd.lib vtkDICOMParser-8.2-gd.lib vtkDomainsChemistry-8.2-gd.lib vtkDomainsChemistryOpenGL2-8.2-gd.lib vtkdoubleconversion-8.2-gd.lib vtkexodusII-8.2-gd.lib vtkexpat-8.2-gd.lib vtkFiltersAMR-8.2-gd.lib vtkFiltersCore-8.2-gd.lib vtkFiltersExtraction-8.2-gd.lib vtkFiltersFlowPaths-8.2-gd.lib vtkFiltersGeneral-8.2-gd.lib vtkFiltersGeneric-8.2-gd.lib vtkFiltersGeometry-8.2-gd.lib vtkFiltersHybrid-8.2-gd.lib vtkFiltersHyperTree-8.2-gd.lib vtkFiltersImaging-8.2-gd.lib vtkFiltersModeling-8.2-gd.lib vtkFiltersParallel-8.2-gd.lib vtkFiltersParallelImaging-8.2-gd.lib vtkFiltersPoints-8.2-gd.lib vtkFiltersProgrammable-8.2-gd.lib vtkFiltersSelection-8.2-gd.lib vtkFiltersSMP-8.2-gd.lib vtkFiltersSources-8.2-gd.lib vtkFiltersStatistics-8.2-gd.lib vtkFiltersTexture-8.2-gd.lib vtkFiltersTopology-8.2-gd.lib vtkFiltersVerdict-8.2-gd.lib vtkfreetype-8.2-gd.lib vtkGeovisCore-8.2-gd.lib vtkgl2ps-8.2-gd.lib vtkglew-8.2-gd.lib vtkGUISupportMFC-8.2-gd.lib vtkhdf5-8.2-gd.lib vtkhdf5_hl-8.2-gd.lib vtkImagingColor-8.2-gd.lib vtkImagingCore-8.2-gd.lib vtkImagingFourier-8.2-gd.lib vtkImagingGeneral-8.2-gd.lib vtkImagingHybrid-8.2-gd.lib vtkImagingMath-8.2-gd.lib vtkImagingMorphological-8.2-gd.lib vtkImagingSources-8.2-gd.lib vtkImagingStatistics-8.2-gd.lib vtkImagingStencil-8.2-gd.lib vtkInfovisCore-8.2-gd.lib vtkInfovisLayout-8.2-gd.lib vtkInteractionImage-8.2-gd.lib vtkInteractionStyle-8.2-gd.lib vtkInteractionWidgets-8.2-gd.lib vtkIOAMR-8.2-gd.lib vtkIOAsynchronous-8.2-gd.lib vtkIOCityGML-8.2-gd.lib vtkIOCore-8.2-gd.lib vtkIOEnSight-8.2-gd.lib vtkIOExodus-8.2-gd.lib vtkIOExport-8.2-gd.lib vtkIOExportOpenGL2-8.2-gd.lib vtkIOExportPDF-8.2-gd.lib vtkIOGeometry-8.2-gd.lib vtkIOImage-8.2-gd.lib vtkIOImport-8.2-gd.lib vtkIOInfovis-8.2-gd.lib vtkIOLegacy-8.2-gd.lib vtkIOLSDyna-8.2-gd.lib vtkIOMINC-8.2-gd.lib vtkIOMovie-8.2-gd.lib vtkIONetCDF-8.2-gd.lib vtkIOParallel-8.2-gd.lib vtkIOParallelXML-8.2-gd.lib vtkIOPLY-8.2-gd.lib vtkIOSegY-8.2-gd.lib vtkIOSQL-8.2-gd.lib vtkIOTecplotTable-8.2-gd.lib vtkIOVeraOut-8.2-gd.lib vtkIOVideo-8.2-gd.lib vtkIOXML-8.2-gd.lib vtkIOXMLParser-8.2-gd.lib vtkjpeg-8.2-gd.lib vtkjsoncpp-8.2-gd.lib vtklibharu-8.2-gd.lib vtklibxml2-8.2-gd.lib vtklz4-8.2-gd.lib vtklzma-8.2-gd.lib vtkmetaio-8.2-gd.lib vtkNetCDF-8.2-gd.lib vtkogg-8.2-gd.lib vtkParallelCore-8.2-gd.lib vtkpng-8.2-gd.lib vtkproj-8.2-gd.lib vtkpugixml-8.2-gd.lib vtkRenderingAnnotation-8.2-gd.lib vtkRenderingContext2D-8.2-gd.lib vtkRenderingContextOpenGL2-8.2-gd.lib vtkRenderingCore-8.2-gd.lib vtkRenderingExternal-8.2-gd.lib vtkRenderingFreeType-8.2-gd.lib vtkRenderingGL2PSOpenGL2-8.2-gd.lib vtkRenderingImage-8.2-gd.lib vtkRenderingLabel-8.2-gd.lib vtkRenderingLOD-8.2-gd.lib vtkRenderingOpenGL2-8.2-gd.lib vtkRenderingVolume-8.2-gd.lib vtkRenderingVolumeOpenGL2-8.2-gd.lib vtksqlite-8.2-gd.lib vtksys-8.2-gd.lib vtktheora-8.2-gd.lib vtktiff-8.2-gd.lib vtkverdict-8.2-gd.lib vtkViewsContext2D-8.2-gd.lib vtkViewsCore-8.2-gd.lib vtkViewsInfovis-8.2-gd.lib vtkzlib-8.2-gd.lib
|
测试代码
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65
| #include <iostream> #include <vector> #include <ctime> #include <pcl/point_cloud.h> #include <pcl/octree/octree.h> #include <boost/thread/thread.hpp> #include <pcl/visualization/pcl_visualizer.h> using namespace std; int main(int argc, char** argv) { srand((unsigned int)time(NULL)); pcl::PointCloud<pcl::PointXYZ>::Ptr cloud(new pcl::PointCloud<pcl::PointXYZ>); cloud->width = 1000; cloud->height = 1; cloud->points.resize(cloud->width * cloud->height); for (size_t i = 0; i < cloud->points.size(); ++i) { cloud->points[i].x = 1024.0f * rand() / (RAND_MAX + 1.0f); cloud->points[i].y = 1024.0f * rand() / (RAND_MAX + 1.0f); cloud->points[i].z = 1024.0f * rand() / (RAND_MAX + 1.0f); }
pcl::octree::OctreePointCloudSearch<pcl::PointXYZ> octree(0.1); octree.setInputCloud(cloud); octree.addPointsFromInputCloud(); pcl::PointXYZ searchPoint; searchPoint.x = 1024.0f * rand() / (RAND_MAX + 1.0f); searchPoint.y = 1024.0f * rand() / (RAND_MAX + 1.0f); searchPoint.z = 1024.0f * rand() / (RAND_MAX + 1.0f);
vector<int>pointIdxRadiusSearch; vector<float>pointRadiusSquaredDistance; float radius = 256.0f * rand() / (RAND_MAX + 1.0f); cout << "Neighbors within radius search at (" << searchPoint.x << " " << searchPoint.y << " " << searchPoint.z << ") with radius=" << radius << endl; if (octree.radiusSearch(searchPoint, radius, pointIdxRadiusSearch, pointRadiusSquaredDistance) > 0) { for (size_t i = 0; i < pointIdxRadiusSearch.size(); ++i) cout << " " << cloud->points[pointIdxRadiusSearch[i]].x << " " << cloud->points[pointIdxRadiusSearch[i]].y << " " << cloud->points[pointIdxRadiusSearch[i]].z << " (squared distance: " << pointRadiusSquaredDistance[i] << ")" << endl; } boost::shared_ptr<pcl::visualization::PCLVisualizer>viewer(new pcl::visualization::PCLVisualizer("显示点云")); viewer->setBackgroundColor(0, 0, 0); pcl::visualization::PointCloudColorHandlerCustom<pcl::PointXYZ>target_color(cloud, 255, 0, 0); viewer->addPointCloud<pcl::PointXYZ>(cloud, target_color, "target cloud"); viewer->setPointCloudRenderingProperties(pcl::visualization::PCL_VISUALIZER_POINT_SIZE, 1, "target cloud");
while (!viewer->wasStopped()) { viewer->spinOnce(100); boost::this_thread::sleep(boost::posix_time::microseconds(1000)); }
return (0); }
|
OpenCV配置
https://blog.csdn.net/Creama_/article/details/107238475
https://blog.csdn.net/Smalldemons/article/details/129723228
配置系统变量
找到OpenCV的安装(解压)路径,将路径opencv\build\x64\vc15\bin添加到Path中。
VC++目录,点击包含目录,然后将OpenCV的三个包含目录添加进去(图中还没加):
D:\opencv\build\include
D:\opencv\build\include\opencv
D:\opencv\build\include\opencv2
添加完后,继续点击库目录,将OpenCV的库目录添加进去:
D:\opencv\build\x64\vc12\lib
添加完后,点击连接器,点击输入,点击附加依赖项,添加lib文件,lib文件可以在D:\Program Files\opencv\build\x64\vc15\lib中查看,数字后面带d的表示debug,选这个就行了(添加依赖项的时候可不用路径,只输入文件名,如:opencv_world411d.lib)。
vcglib配置
在打开的项目属性页,配置属性
一栏,找到VC++目录
–>包含目录
,将其设置为
1
| path/to/your/include/vcg
|
点击C/C++
一栏,找到预处理
–>预处理器定义
,输入
1 2 3 4 5
| _CRT_SECURE_NO_WARNINGS 参数说明: 这个宏用于禁用微软C运行库(CRT)中关于安全函数的警告。 在Visual Studio中,使用不安全的函数(如strcpy、sprintf等)会触发编译器警告,建议改用更安全的替代函数(如strcpy_s、sprintf_s等)。 定义CRT_SECURE_NO_WARNINGS可以抑制这些警告,从而编译通过,但要注意,这样做可能会增加代码存在安全漏洞的风险。
|
C++常识
一些常见问题
解决压缩包问题后的DLL缺失
压缩包问题解决后,运行程序时又提示缺少“luad.dll”。这种问题在网上很难找到明确的解决方法。尝试了各种途径,最终通过安装lua for Windows修复了这个问题。安装完成后,系统能够正确识别并加载“luad.dll”,程序也终于得以顺利运行。
Python
GrowSP项目
1.官网下载conda包(4090无法连接网络404)
https://anaconda.org/conda-forge/qhull/files?version=2015.2
2.AttributeError: ‘numpy.ndarray’ object has no attribute ‘numpy‘:
删掉.numpy()
3.78行:
1
| coords = coords.astype(np.float32)
|
4.MinkowskiEngine安装总结
MinkowskiEngine安装避坑:https://blog.csdn.net/qq_52297947/article/details/126706762
建议直接github下
5.ValueError: Unknown CUDA arch (8.9) or GPU not supported 报错处理
在RTX4090上运行深度学习代码报错:ValueError: Unknown CUDA arch (8.9) or GPU not suppor。
原因是cuda(我这里是cuda11.0,最高支持8.6)的版本不支持当前算力(8.9)
解决办法(我这是 Ubuntu 系统),改算力:
1 2 3 4 5 6
| sudo vim ~/.bashrc
# 在配置文件中添加如下一行
export TORCH_CUDA_ARCH_LIST=8.6 # 因为是CUDA11.0,对应的算力为8.6 source ~/.bashrc
|
nvidia给的显卡算力查询:CUDA GPU | NVIDIA 开发者https://developer.nvidia.cn/cuda-gpus#compute
6./usr/local/cuda/bin/nvcc: No such file or directory 错误
先确定 cuda 是否安装成功
安装成功的话直接在命令行里输入
1
| export CUDA_HOME=/usr/local/cuda
|
7.pclpy 安装和使用
建议直接找github https://github.com/davidcaron/pclpy 或 https://blog.csdn.net/m0_73126623/article/details/136180532
conda install qhull==20xx.x
-c conda-forge(如果报错“ImportError: libqhull_p.so.7: cannot open shared object file”的话)
8.【anaconda】conda创建、查看、删除虚拟环境(anaconda命令集)
https://blog.csdn.net/miracleoa/article/details/106115730