前言
首先不建議windows下源碼編譯,需要用C++的可以直接下載官網(wǎng)編譯好的版本。熟悉vcpkg的,可以把open3d加到vcpkg使用,參考該博客。
1.編譯環(huán)境
- cmake >=3.20
- python >=3.6.0
- visual studio >=2017
2.編譯步驟
- Github下載open3d源碼
- 打開源碼,新建build文件夾
mkdir build
cd build
cmake -G "Visual Studio 16 2019" -A x64 -DCMAKE_INSTALL_PREFIX="<open3d_install_directory>" ..
填寫你的VS版本,例vs2022(17),open3d_install_directory使用當(dāng)前路徑".",最終命令為:
cmake -G "Visual Studio 17 2022" -A x64 -DCMAKE_INSTALL_PREFIX="." ..
- 編譯,會(huì)出現(xiàn)一系列錯(cuò)誤,按照提示解決。重復(fù)編譯過程直至沒有Error提示
cmake --build . --config Release --target ALL_BUILD
- 安裝,生成include和lib
cmake --build . --config Release --target INSTALL
3.編譯中的bug
3.1 下載超時(shí)問題,ispc、pybind11、open3d_sphinx_theme等
報(bào)錯(cuò)信息類似:
error : downloading 'https://github.com/xxx/'
- 開vpn手動(dòng)點(diǎn)擊報(bào)錯(cuò)鏈接中的url用瀏覽器下載,然后復(fù)制粘貼到"Open3D-master\3rdparty_downloads"相應(yīng)的庫文件下。
- 替換相應(yīng)文件下的未下載完成的文件,例如:下載pybind11-2.6.2.tar.gz改名替換為Open3D-master\3rdparty_downloads\pybind11\v2.6.2.tar.gz。
- one-20190522.tar.gz 是parallelstl庫下的文件 -> 20190522.tar.gz
- 建議先把boringssl、curl這兩個(gè)庫替換好,curl是下載用的庫。下好后可能以上的超時(shí)問題會(huì)消失一些,博主本人是一個(gè)個(gè)替換的,最后才根據(jù)cmake報(bào)錯(cuò)裝的curl
3.2 boringssl
這個(gè)庫的下載路徑不存在,所以需要去GitHub下載boringssl-master.zip
- 解壓后用7z壓成.tar
- 把.tar壓成gzip
- 把boringssl-master.tar.gz改名替換boringssl_edfe413_win_amd64.tar.gz
3.3 DirectXMath、DirectXHeaders
fatal: unable to access 'https://github.com/microsoft/DirectXMath.git/': Failed to connect to github.com port 443 aft
er 21085 ms: Timed out
博主的 curl 下載并編譯好后,會(huì)自動(dòng)下載裝好。上述方法不行試試,github下載了DirectX-Headers-mains和DirectXMath-main,并解壓到build\uvatlas\src\ext_directxheaders和build\uvatlas\src\ext_directxmath
4.驗(yàn)證編譯是否成功
隨便打開build\bin\examples\Release\下的例程,例如:Draw.exe
5.新建項(xiàng)目中使用
PS:3d庫都是縫合怪
新建一個(gè)C++項(xiàng)目
- 包含Build下的include、include\open3d\3rdparty
- 打開build/open3d.sln 找到 example/cpp中的任意一個(gè)項(xiàng)目
- 庫目錄添加build\bin\Release路徑,然后照抄范例中的附加目錄
- 照抄范例的預(yù)處理器,不然會(huì)報(bào)錯(cuò)fmn重復(fù)定義(LNK2005) 等錯(cuò)誤
- 項(xiàng)目需Release-x64的項(xiàng)目,Debug需要重編譯
- 項(xiàng)目->屬性->c/c++代碼生成 更改成 “多線程(/MT)”
插入如下代碼:
#include <iostream>
#include "open3d/Open3D.h"
using namespace open3d;
int main(){
// 從github上下載pcd文件,也可以自己找一個(gè)pcd文件
auto demo_crop_data = data::DemoCropPointCloud();
auto cloud_ptr = std::make_shared<geometry::PointCloud>();
if (io::ReadPointCloud(demo_crop_data.GetPointCloudPath(),*cloud_ptr)) {
utility::LogInfo("Successfully read {}",demo_crop_data.GetPointCloudPath());
} else {
utility::LogWarning("Failed to read {}",demo_crop_data.GetPointCloudPath());
return 1;
}
cloud_ptr->NormalizeNormals();
visualization::DrawGeometries({ cloud_ptr },"PointCloud",1600,900);
}
6.靜態(tài)庫整合
上面鏈接的靜態(tài)庫太多,故使用visual studio工具lib.exe(官方文檔)進(jìn)行合并,簡(jiǎn)化調(diào)用流程。由于lib.exe的合并的函數(shù)限制,把上面的的靜態(tài)鏈接庫按照體積分兩份。
6.1 Lib.exe簡(jiǎn)單使用
輸入cmd命令lib.exe /out:xmv1.lib Open3D.lib assimp-vc143-mt.lib 等
可以用python處理之前的鏈接路徑,最后得到所有鏈接路徑(絕對(duì)路徑)。還沒看懂的可以去看看這篇博客。
最后多個(gè)靜態(tài)鏈接合并成xmv1.lib和xmv.lib
6.2 簡(jiǎn)化后的調(diào)用流程
-
添加頭文件,包含build下的include、include\open3d\3rdparty
D:\3rdparty\Open3D-master\build\include D:\3rdparty\Open3D-master\build\include\open3d\3rdparty
-
引用鏈接庫
#pragma comment(lib, "xmv.lib") #pragma comment(lib, "xmv1.lib")
-
添加預(yù)處理器文章來源:http://www.zghlxwxcb.cn/news/detail-446508.html
%(PreprocessorDefinitions) WIN32 _WINDOWS _CRT_SECURE_NO_WARNINGS NDEBUG OPEN3D_CXX_STANDARD="14" OPEN3D_CXX_COMPILER_ID="MSVC" OPEN3D_CXX_COMPILER_VERSION="19.34.31933.0" OPEN3D_CUDA_COMPILER_ID="" OPEN3D_CUDA_COMPILER_VERSION="" ZMQ_STATIC BUILD_ISPC_MODULE BUILD_GUI BUILD_WEBRTC WITH_IPPICV _GLIBCXX_USE_CXX11_ABI=0 WINDOWS _CRT_SECURE_NO_DEPRECATE _CRT_NONSTDC_NO_DEPRECATE _SCL_SECURE_NO_WARNINGS NOMINMAX _USE_MATH_DEFINES _ENABLE_EXTENDED_ALIGNED_STORAGE __TBB_LIB_NAME=tbb_static OPEN3D_STATIC GLEW_STATIC FMT_HEADER_ONLY=0 FMT_USE_WINDOWS_H=0 FMT_STRING_ALIAS=1 TINYGLTF_IMPLEMENTATION STB_IMAGE_IMPLEMENTATION STB_IMAGE_WRITE_IMPLEMENTATION TINYOBJLOADER_IMPLEMENTATION MKL_ILP64 CMAKE_INTDIR="Release"
-
調(diào)用代碼文章來源地址http://www.zghlxwxcb.cn/news/detail-446508.html
#include <iostream> #pragma comment(lib, "xmv.lib") #pragma comment(lib, "xmv1.lib") #include "open3d/Open3D.h" using namespace open3d; int main() { auto demo_crop_data = data::DemoCropPointCloud(); auto cloud_ptr = std::make_shared<geometry::PointCloud>(); if (io::ReadPointCloud(demo_crop_data.GetPointCloudPath(),*cloud_ptr)) { utility::LogInfo("Successfully read {}",demo_crop_data.GetPointCloudPath()); } else { utility::LogWarning("Failed to read {}",demo_crop_data.GetPointCloudPath()); return 1; } auto redWoodRGBD = data::SampleRedwoodRGBDImages(); auto image_ptr = std::make_shared<geometry::Image>(); if (io::ReadImage(redWoodRGBD.GetColorPaths()[0],*image_ptr)) { utility::LogInfo("Successfully read {}",redWoodRGBD.GetColorPaths()[0]); } else { utility::LogWarning("Failed to read {}",redWoodRGBD.GetColorPaths()[0]); return 1; } }
到了這里,關(guān)于手把手教你在windows下源碼編譯Open3D的文章就介紹完了。如果您還想了解更多內(nèi)容,請(qǐng)?jiān)谟疑辖撬阉鱐OY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章,希望大家以后多多支持TOY模板網(wǎng)!