Open3D cpp interface and "make install"

Created on 2 Feb 2018  路  30Comments  路  Source: intel-isl/Open3D

Hi, authors,

If I want to use Open3D as a substitute for PCL to deal with 3D data manipulation and visualization (my system uses CMake for project building). What cmake instructives should I append in my CMakeLists.txt file? It'll be very useful to have an example of CMakeLists.txt and also a simple example on how to call Open3D C++ interface.

THX!

docs enhancement

Most helpful comment

That's good point. As mentioned above, we have several cpp examples. The cpp examples should be self-explanatory. They are hidden gem of Open3D that are used in our past projects, and some of nice applications (like cropping point cloud) are not addressed in Python Tutorial. Our intention was to guide Open3D users to be familiar with Python environment first.

The best answer for your question for now is to add your custom cpp file in src/Test folder and add entry of your application in src/Test/CMakeList.txt file. The Open3D build chain will generate standard-alone executable for you.

I began to consider adding a getting started guide for cpp examples. Please stay tuned!

All 30 comments

We don't have detailed documentation for the cpp interface.
But there are examples in:
https://github.com/IntelVCL/Open3D/tree/master/src/Test
and
https://github.com/IntelVCL/Open3D/tree/master/src/Tools
Hope they are helpful.

That's good point. As mentioned above, we have several cpp examples. The cpp examples should be self-explanatory. They are hidden gem of Open3D that are used in our past projects, and some of nice applications (like cropping point cloud) are not addressed in Python Tutorial. Our intention was to guide Open3D users to be familiar with Python environment first.

The best answer for your question for now is to add your custom cpp file in src/Test folder and add entry of your application in src/Test/CMakeList.txt file. The Open3D build chain will generate standard-alone executable for you.

I began to consider adding a getting started guide for cpp examples. Please stay tuned!

It would also be really nice if "make install" could install a Open3D-config.cmake. Ideally with the new cmake style of exporting targets instead of the old OPEN3D_LIBRARIES, OPEN3D_INCLUDE_DIRS style.
That would allow people to just use the standard cmake FindPackage() function.

It would be nice if someone is interested in building the "make install" function for Open3D. I started it in 2015 (that's why it is very old style!) and have not got time to finish it.

Can anyone contribute a PR?

Qianyi, you mentioned you might have a few ideas on how to best approach this.
Just a note for you to send me the resources when you have time.

There are two parts:

  • Setup make install
  • Setup C++ interface

This is also related to #234

To set up make install, we only need to edit the cmake files. Just see what glfw has done:
https://github.com/glfw/glfw/blob/0d4534733b7a748a21a1b1177bb37a9b224e3582/CMakeLists.txt
https://github.com/glfw/glfw/blob/0d4534733b7a748a21a1b1177bb37a9b224e3582/src/CMakeLists.txt
We probably need an uninstall recipe too, example:
https://github.com/glfw/glfw/blob/0d4534733b7a748a21a1b1177bb37a9b224e3582/cmake_uninstall.cmake.in
PCL has done it too. Take a look if you are interested (https://github.com/pointcloudlibrary/pcl).

Once make install has been set up. We can see how to link external C++ projects to Open3D (installed version). PCL has a tutorial for itself:
http://pointclouds.org/documentation/tutorials/using_pcl_pcl_config.php#using-pcl-pcl-config

We do something similar.

Finally we need to write a tutorial about it.

Hello,i work on windows and vs2017, but i find that thers are just pyhon interfaces,i want to compile c++ headers and lib files ,but i dont know how to write CMakeList.txt , .

we all beleive u are doing such works ,just want to know if works have done.

thanks!

IMHO there are some issues we need to address in order to consider this done. I mention here a few:

  • recursively install all the necessary headers.
    Something like install(FILES ${INCLUDE_FILES} DESTINATION include) seems insufficient.
    The other option: install(DIRECTORY ... DESTINATION include/Open3D COMPONENT Devel FILES_MATCHING PATTERN "*.h") didn't work for me, I got a weird permission error.
  • address header dependencies on External.
    I propose that ideally we shouldn't have to provide headers for any of the libraries in External, that is bad practice.
  • maintain header directory structure after install.
    This should be handled by something like install(DIRECTORY ... DESTINATION include/Open3D COMPONENT Devel FILES_MATCHING PATTERN "*.h") however, as I mentioned above, it failed on my system.
  • install to bin/open3d, lib/open3d and include/open3d
  • add FindOpen3D.cmake.
    This will enable find_package(Open3D) functionality for new c++ projects with cmake.
  • separate the c++ samples (called Test) from the main build.
    These sample should build based only on Open3D installed files.
    Keep the Test source where it is in the repo.
  • include the c++ samples in the install.
    Let the user choose the install destination of Test as part of the cmake config for Open3D.

All of these are open for discussion.

To follow up with the discussion in #293
The first few points seem to be more useful and urgent. We don't need to worry about find_package so far. But it is good to have a PR just ship in the make install function that copies (installs) the library to system path.

It seems the current CMake rules do not include installation instructions for various lib and bin components.
The same applies for the TestData and Tutorial directories.

@qianyizh In that sense, the #298 PR already covers the first four points.
The only difference with my PR is that lib and bin does not have open3d sub-directory, because it just does not make sense for me.
Furthermore, many libraries (e.g., OpenCV) does not utilize lib/[name] or bin/[name], so why should we?

Agree. We don't need open3d subdirectory. @syncle @takanokage please take a look.

Is there documentation on the instructions I need to add to my CMake file to include Open3D in my C++ project?
I've done find_package(Open3D)but CMake can't find Open3D. I'm on Windows.

This function is currently experimental. But we have got success on a few different operating systems.
Can you try to follow this tutorial:
http://www.open3d.org/docs/tutorial/C++/cplusplus_interface.html
See if you can make it work? Post problems you have encountered in this thread.

Sure, I tried it. But I got this error -

CMake Error at CMakeLists.txt:40 (message):
Open3D not found

What's your operation system?
When you compile Open3D, you should run make install, it will install all the files into a folder.
When you do find_package, you can give a hint to the CMake file in Open3D installed location.

I'm on Windows. I used the CMake GUI to compile Open3D from source. Then in Visual Studio 2017 64bit I built ALL_BUILD, INSTALL projects.

In that case, your Open3D installation should appear in something like: C:\Program Files\Open3D\CMake, you can feed this path to:

find_package(Open3D    QUIET HINTS "~/open3d_install/lib/CMake")

Can you try it?
I don't have a Windows machine at my hand, but I think either @syncle or @takanokage have successfully tested it on Windows before.

Sure, I'm trying it.
This is the new line -

find_package(Open3D QUIET HINTS "D:/Workspace/Ext. Source Code/Open3D/build/CMake")

This doesn't work either.
Which folder do I need to put in that line for the hint? CMake isn't a directory inside Open3D/build. CMake directory only exists inside "~/open3d_install/src/CMake"

It is supposed to be your install folder.
When you compile the "INSTALL" object, it copies lots of files (exe, dll, lib, h) to your program install folder (C:\program files\Open3D, or a customized folder you specified with CMAKE_INSTALL_PREFIX when you setup CMake for Open3D source code). You should be able to find these copy commands in your "output" panel (at the bottom of Visual Studio). You may find your install folder there. And CMake is a subfolder that includes "FindOpen3D.cmake".

Also, note that if you haven't specified "CMAKE_INSTALL_PREFIX" when you compile Open3D source, by default it installs into "C:\program files\Open3D". It requires Visual Studio to be running with Administrator privilege (you can right click the Visual Studio shortcut icon and choose "run as administrator"). Or when you build INSTALL object you may fail (but you may not have noticed, :)

Ah, so that worked out great. Now I'm able to generate the project, sln files and open it up in Visual Studio.
However, when I build my project in VS, I get a linker error

Error LNK1104 cannot open file 'Open3D.lib'
TestVisualizer
D:\Workspace\Ext. Source Code\Open3D test\build\LINK 1

Umm, I really need to have access to a windows machine in order to help you test this. @syncle can you help with this issue?

The error looks like Open3D.lib is not at the specified path. Can you manually check? Open project property, go to link (linker?) panel, first check additional linker dir, then check the library name (I forgot if it is absolute path or relative path. If it is the latter, the right directory path should be added to additional linker dir).

This may very likely to be a bug in findopen3d.cmake. I don鈥檛 think it has been thoroughly tested on windows. Last time I had a similar issue and I had to manually fix it with Visual Studio project settings (as I described in my last post). I can double check when I can have access of a windows machine tomorrow.

I manually checked the project properties in VS and this is what there is.

  1. Additional library directories -
    1
  1. Additional Dependencies -
    2

Yes. Can you add this to additional library directory: c:\program filesopen3dlib\

And make sure you have Open3D.lib in that folder.

That error is gone. But it says

Error LNK1104 cannot open file 'glfw.lib'

Should I rename glfw to glfw3 in the CMake file? There is no glfw.lib file in the lib directory.

Yes.

It builds now! Phew

So its clear that there are 2 issues with this workflow (at least on Windows)

  1. The first is including "C:/Program Files/Open3D/lib" in Additional Library Directories
    This can be solved by moving
    link_directories(${Open3D_LIBRARY_DIRS})
    to be above
    add_executable(TestVisualizer TestVisualizer.cpp) .
    Currently it is the other way around so the link_directories isn't processed.

  2. Renaming glfw to glfw3.
    We need to rename glfw to glfw3 in this line
    set(Open3D_LIBRARIES "Open3D;glew;glfw;opengl32;jpeg;jsoncpp;png;zlib;tinyfiledialogs") . This is in the file Open3DConfig.cmake
    For now I will be using this line in my CMakeLists file -
    set(Open3D_LIBRARIES "Open3D;glew;glfw3;opengl32;jpeg;jsoncpp;png;zlib;tinyfiledialogs")

How does not renaming glfw work in Ubuntu? Seems like it should be an issue regardless of OS.

@takanokage @yxlao: can you guys confirm that this issue had been addressed in v0.3?

@syncle I believe this issue has been addressed now. First make install target was added. Second, CIs for linking an example program to libraries installed by make install as been added (https://github.com/IntelVCL/Open3D/pull/548 and https://github.com/IntelVCL/Open3D/pull/568). Thus I'll recommend closing this PR.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

taochenshh picture taochenshh  路  3Comments

Prakash19921206 picture Prakash19921206  路  4Comments

masonsun picture masonsun  路  3Comments

mike239x picture mike239x  路  4Comments

nrj127 picture nrj127  路  4Comments