Below specifies instructions for building open3d w/ headless rendering flags on crv, without sudo.
This requires OSMesa. With sudo it's very easy to install. Without sudo it's still doable but requires manually building LLVM and several other packages. The benefit is that once you do this you can render headlessly w/o having to open an extra viewer like turboVNC.
NOTE: in the installation process below we set a lot of environment variables in the terminal (PATH, LD_LIBRARY_PATH, CPLUS_INCLUDE_PATH, C_INCLUDE_PATH
). If you change to a different terminal then you will need to set these variables again. If you want the variables to always be set, add the corresponding commands to ~/.bashrc
.
crv's default cmake is too outdated for building Open3D. We need to install a newer version.
- Download cmake binary distributions from here. It should be a
tar.gz
file. - Unzip the downloaded
tar.gz
file and addcmake-XXX/bin
folder toPATH
. - Check to see that
which cmake
outputs the folder you just unzipped, not the default cmake.
We need ninja for building LLVM (step 3) and Open3d.
- Download ninja binary distributions from here. It should be named
ninja-linux.zip
. - Unzip
ninja-linux.zip
, it should have an executable called ninja in the zip file. Add the folder containing this executable toPATH
. - Check to see that
which ninja
outputs the folder that has the ninja executable.
The pre-built OSMesa we use (in step 4) requires libLLVM-6.0.so.1
, which is obtained by building LLVM 6.0.x.
We build LLVM 6.0.1. We adapt the instructions from here (Following the instructions in the URL does not produce libLLVM-6.0.so
-- we need additional build flags.)
- Download the LLVM 6.0.1 source code from here. By the time of writing this corresponds to this link:
https://releases.llvm.org/6.0.1/llvm-6.0.1.src.tar.xz
- Unzip the
tar.xz
file. It should give you a folder calledllvm-6.0.1.src
. Moving forward we use/path/to/llvm-src/
to denote the path to this folder. - Create a directory in which you want to put the build folder and the built libraries. Moving forward we use
/path/to/llvm
to denote the path to this folder (Note: /path/to/llvm must be different from /path/to/llvm-src). Create abuild
folder under/path/to/llvm
. cd to this directory:
mkdir /path/to/llvm
mkdir /path/to/llvm/build
cd /path/to/llvm/build
- Generate build files and build using ninja
cmake /path/to/llvm-src \
-DCMAKE_INSTALL_PREFIX=/path/to/llvm \
-DLLVM_ENABLE_FFI=ON \
-DCMAKE_BUILD_TYPE=Release \
-DLLVM_BUILD_LLVM_DYLIB=ON \
-DLLVM_LINK_LLVM_DYLIB=ON \
-DLLVM_BUILD_TESTS=ON \
-DLLVM_ENABLE_RTTI=ON \
-Wno-dev -G Ninja .. &&
ninja
- Move the built files into
/path/to/llvm
by runningninja install
. - To confirm that build is successful, we check that
libLLVM-6.0.so
is generated and can find all its dependencies:
cd /path/to/llvm/lib
ldd libLLVM-6.0.so
The output of ldd
should indicate that all dependencies of libLLVM-6.0.so
are found.
- We need to make sure that OSMesa can find
libLLVM-6.0.so.1
. The built files do not containlibLLVM-6.0.so.1
, but containlibLLVM-6.0.so
. So we need to first make a soft link fromlibLLVM-6.0.so.1
tolibLLVM-6.0.so
:
ln -s /path/to/llvm/lib/libLLVM-6.0.so /path/to/llvm/lib/libLLVM-6.0.so.1
We then need to make sure that the folder containing libLLVM-6.0.so.1
is added to LD_LIBRARY_PATH
so OSMesa can find it:
export LD_LIBRARY_PATH=/path/to/llvm/lib:$LD_LIBRARY_PATH
ldconfig
Note: After you build Open3D successfully, everytime you run it (import open3d
), it needs to find libLLVM-6.0.so.1
. You might want to add export LD_LIBRARY_PATH=/path/to/llvm/lib:$LD_LIBRARY_PATH
to your ~/.bashrc
so you don't have to manually type it in every time you start a new terminal and try to run Open3D.
Open3D w/ headless rendering requires us to build OSMesa. I tried building OSMesa from source but encountered more errors and packages not found. So instead I chose to use the .deb
package someone provided in their instructions of building OSMesa.
Note that the usual way of installing .deb
, which is to run dpkg -i
, does not work without sudo. Therefore we choose to extract the package first and then manually add the necessary paths for building Open3d.
- Create a folder under which you want to put the OSMesa files. Moving forward we use
/path/to/mesa
to denote the path to this folder. - Download the
.deb
file and unzip usingdpkg -x
:
wget https://github.com/mmatl/travis_debs/raw/master/xenial/mesa_18.3.3-0.deb
dpkg -x mesa_18.3.3-0.deb /path/to/mesa
Note that dpkg -x
creates usr/local
folders under the unzipped folder by default. The mesa libraries are in /path/to/mesa/usr/local/lib
, and the mesa header files are in /path/to/mesa/usr/local/include
.
- Verify that
libOSMesa.so
can find all its dependencies (including thelibLLVM-6.0.so.1
we added from installing LLVM):
ldd /path/to/mesa/usr/local/lib/libOSMesa.so
The output of ldd should indicate that all dependencies are found.
- Add the folder that contains mesa header files so that
gcc
andg++
can find them:
CPLUS_INCLUDE_PATH=/path/to/mesa/usr/local/lib:$CPLUS_INCLUDE_PATH
C_INCLUDE_PATH=/path/to/mesa/usr/local/lib:$C_INCLUDE_PATH
- Add the mesa libraries to
LD_LIBRARY_PATH
, so they can be found when building Open3d:
export LD_LIBRARY_PATH=/path/to/mesa/usr/local/lib:$LD_LIBRARY_PATH
ldconfig
git clone
the Open3d to some folder. Moving forward we use/path/to/Open3D
to refer to this folder:
git clone /path/to/Open3D
cd /path/to/Open3D
mkdir build && cd build
- Generate build files:
cmake -DENABLE_HEADLESS_RENDERING=ON \
-DCMAKE_PREFIX_PATH=/path/to/mesa/usr/local/lib \
-DBUILD_GUI=OFF \
-DUSE_SYSTEM_GLEW=OFF \
-DUSE_SYSTEM_GLFW=OFF \
..
- Create a python virtual environment and enter into it, or enter into a pre-existing venv. open3d will be installed in this venv.
- Build Open3D
make -j8
make install-pip-package
- Test it by
import open3d
in python terminal and try to render something headlessly!