Compiling Open3D with windows 10

1, Relevant environment

System: windows10
CMake: 3.21.4
Visual Studio: 2019
Open3D: 0.12.0

2, Source code compilation

2.1 download source code

git clone --recursive https://github.com/intel-isl/Open3D

If the Internet is too slow, you can use the acceleration interface

git clone https://github.com.cnpmjs.org/isl-org/Open3D.git
# git clone https://hub.fastgit.org/isl-org/Open3D.git
# git clone https://github.91chi.fun//https://github.com/isl-org/Open3D.git

2.2 switch to the specified branch

After downloading, enter the Open3D directory, view the branch with git tag, and then switch to the specified branch. Here, switch to 0.12.0

git checkout v0.12.0

2.3 update the third party Library

  • Modify the Open3D directory The address in the gitmodules file is replaced by the acceleration address, such as
[submodule "3rdparty/pybind11"]
	path = 3rdparty/pybind11
	url = https://github.com/pybind/pybind11.git

Replace with

[submodule "3rdparty/pybind11"]
	path = 3rdparty/pybind11
	url = https://github.com.cnpmjs.org/pybind/pybind11.git
  • Execute the following command
git submodule sync
git submodule update --init --recursive

2.4 compilation

  • Using CMake, select the resource path and compilation path, and click Configure and Generate
  • Open open3d in the build directory with Visual Studio 2019 SLN project

    Select all in the cmakepredefined targets directory_ Build as the startup item, select Release, and click rebuild to compile.
    be careful
    • Choose to open VS2019 as an administrator when compiling, because the generated directory is in the C:/Program Files (x86) directory by default.
    • In addition, I failed to download the filing library during compilation. I downloaded ~ \ open3d \ 3rdparty \ filing \ filing first_ download. The library file specified in the cmake file, and then save it to ~ \ open3d \ 3rdparty_ Downloads \ filing and file the filing_ download. Change the link in the cmake file to the local save path.

3, Installation

In the cmakepredefined targets directory, select INSTALL as the startup item and click generate.
Automatically saved in the C:/Program Files (x86) directory. If the installation is successful, there will be four folders: bin, cmake, include and lib.

4, Testing

reference resources C++ interface Download first TestVisualizer.cpp and CMakeLists.txt
Store it in the user-defined directory, and then use CMake to Configure and Generate.

During the test, there was a mismatch of "RuntimeLibrary": the value "MT_StaticRelease" did not match the value "md_dynamicrelease". Refer to the differences between MT (multi-threaded static version) and MD (multi-threaded dynamic version), MTD and MDD Differences between VS runtime MT and MD.
The solution is as follows:
Select the project, right-click the attribute, click C / C + + = = > code generation = = > runtime, and select MT.
Or directly at cmakelists Txt file.

After compilation, run the following command to get the results:

 .\TestVisualizer.exe pointcloud  "D:/test.pcd"

set(CMAKE_CXX_FLAGS_RELEASE "/MT")
set(CMAKE_CXX_FLAGS_DEBUG "/MTd")
  • TestVisualizer.cpp
Click to expand: Test visualizer cpp
// ----------------------------------------------------------------------------
// -                        Open3D: www.open3d.org                            -
// ----------------------------------------------------------------------------
// The MIT License (MIT)
//
// Copyright (c) 2018 www.open3d.org
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
// IN THE SOFTWARE.
// ----------------------------------------------------------------------------

#include <iostream>
#include <memory>
#include <thread>

#include <Open3D/Open3D.h>

// A simplified version of examples/Cpp/Visualizer.cpp to demonstrate linking
// an external project to Open3D.
int main(int argc, char *argv[]) {
    using namespace open3d;

    utility::SetVerbosityLevel(utility::VerbosityLevel::Debug);
    if (argc < 3) {
        utility::LogInfo("Open3D {}\n", OPEN3D_VERSION);
        utility::LogInfo("\n");
        utility::LogInfo("Usage:\n");
        utility::LogInfo("    > TestVisualizer [mesh|pointcloud] [filename]\n");
        // CI will execute this file without input files, return 0 to pass
        return 0;
    }

    std::string option(argv[1]);
    if (option == "mesh") {
        auto mesh_ptr = std::make_shared<geometry::TriangleMesh>();
        if (io::ReadTriangleMesh(argv[2], *mesh_ptr)) {
            utility::LogInfo("Successfully read {}\n", argv[2]);
        } else {
            utility::LogWarning("Failed to read {}\n\n", argv[2]);
            return 1;
        }
        mesh_ptr->ComputeVertexNormals();
        visualization::DrawGeometries({mesh_ptr}, "Mesh", 1600, 900);
    } else if (option == "pointcloud") {
        auto cloud_ptr = std::make_shared<geometry::PointCloud>();
        if (io::ReadPointCloud(argv[2], *cloud_ptr)) {
            utility::LogInfo("Successfully read {}\n", argv[2]);
        } else {
            utility::LogWarning("Failed to read {}\n\n", argv[2]);
            return 1;
        }
        cloud_ptr->NormalizeNormals();
        visualization::DrawGeometries({cloud_ptr}, "PointCloud", 1600, 900);
    } else {
        utility::LogWarning("Unrecognized option: {}\n", option);
        return 1;
    }
    utility::LogInfo("End of the test.\n");

    return 0;
}

  • CMakeLists.txt
Click to expand: cmakelists txt
cmake_minimum_required(VERSION 3.10)
project(TestVisualizer)

set(CMAKE_CXX_STANDARD 11)

set(OPEN3D_ROOT "C:/Program Files (x86)/Open3D")

set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${Open3D_C_FLAGS}")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${Open3D_CXX_FLAGS}")
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} ${Open3D_EXE_LINKER_FLAGS}")
set(CMAKE_CXX_FLAGS_RELEASE "/MT")
set(CMAKE_CXX_FLAGS_DEBUG "/MTd")

# # Mode 1
#link_directories(${OPEN3D_ROOT}/lib)
#add_executable(${PROJECT_NAME} TestVisualizer.cpp)
#target_link_libraries(${PROJECT_NAME} Open3D::Open3D)   # release
#target_include_directories(${PROJECT_NAME} PUBLIC ${OPEN3D_ROOT}/include)

# # Mode II
find_package(Open3D HINTS ${OPEN3D_ROOT}/CMake)
# Set OS-specific things here
if(WIN32)
elseif(CYGWIN)
elseif(APPLE)
elseif(UNIX)
	add_definitions(-DUNIX)
	add_compile_options(-Wno-deprecated-declarations)
	add_compile_options(-Wno-unused-result)
    add_definitions(-O3)
endif(WIN32)

# Open3D
if (Open3D_FOUND)
    message(STATUS "Found Open3D ${Open3D_VERSION}")

    # link_directories must be before add_executable
    link_directories(${Open3D_LIBRARY_DIRS})

    add_executable(TestVisualizer TestVisualizer.cpp)

    target_link_libraries(TestVisualizer ${Open3D_LIBRARIES})

    target_include_directories(TestVisualizer PUBLIC ${Open3D_INCLUDE_DIRS})

    # Hot fix windows dll not found issue, assumming we're using the Release build
    option(BUILD_SHARED_LIBS "Whether Open3D was build as shared library" OFF)
    if(WIN32 AND BUILD_SHARED_LIBS)
        message("Will copy Open3D.dll to ${CMAKE_CURRENT_BINARY_DIR}/Release")
        add_custom_command(TARGET TestVisualizer POST_BUILD
                        COMMAND ${CMAKE_COMMAND} -E copy
                                ${CMAKE_INSTALL_PREFIX}/bin/Open3D.dll
                                ${CMAKE_CURRENT_BINARY_DIR}/Release)
    endif()

else ()
    message(SEND_ERROR "Open3D not found")
endif ()

5, Reference link

Compiling from source
C++ interface

Keywords: tools

Added by bloodl on Thu, 20 Jan 2022 03:49:16 +0200