K. Lykov Blog

OpenVDB Build on MacOS

OpenVDB is a new library by DreamWorks which contains data structures and tools for work with three-dimensional grid. For instance, it can be used to work with level-sets. On the openvdb web site it is written that it is checked to be build only on RedHat Linux, so I decided to save my experience about making it on the MacOS (Lion, 10.7.5), with gcc 4.7.2 and openvdb-v0-103-1.

There are two ways of building openvdb - build it under Houdini environment (you need to install houdini) and the second way using macport(no need in Houdini, this way is described in the post). In order to build openvdb using Houdini, go to Applications/Houdini/Houdinishell.terminal. In this terminal, several environment variables are set (those used in the Makefile). Houdini sdk(called HDK) contains all dependencies except cppunit and glfw. If you use gcc4.6 or older, just make and everything should be built. Yet, you may have problems with vdb_view, they are fixed in the patch, have a look inside. If you use a newer version, you will have problems with the HDK’s boost which is 1.46. I just renamed the folder with boost in hdk and specified path to a more recent version. Just in case if you forgot, if you want to build openvdb with sudo, you need to use sudo -E instead in order to have all environment variables on place.

Now, how to build OpenVDB without using Houdini and with the modern gcc. First of all, you need to have macports installed, then I would recommend to install the latest gcc. After that install OpenVDB dependencies:

1
2
3
4
sudo port install boost
sudo port install tbb
sudo port install openexr
sudo port install cppunit

The only problem is to install optional package glfw (download sources):

1
2
3
4
5
unzip glfw-2.7.7.zip
cd glfw-2.7.7
make cocoa
export PREFIX=<installation path>
make cocoa-install

pkg-config libglfw.pc In order to simplify linkage of openvdb with glfw (it requires opengl and cocoa), do pkg-config in glwf home:

1
2
3
4
sudo port install pkg-config
cd pkg-config
pkg-config libglfw.pc
export PKG_CONFIG_PATH=<path to directory containing libglfw.pc>

After that you need to set up paths to libraries and includes in Makefile in the openvdb directory. I made several modifications in the openvdb, all of them can be extracted from the patch: - modified Makefile - added boost-system-mt library, added dependencies for vdb_view and other changes - modified vdb_view code so it can work with OpenGL 2.1 and GLSL version 120 - modified one test which can not be compiled without a error in the gcc4.7.2

In order to apply patch:

1
patch -p1 < openvdb-0-103-1-mac-os-10.7.5.patch

When you are done, run make, make install in the OpenVDB src directory. You may try to run vdb_view from the bin directory in the your openvdb installation path. In order to do that, download on of the shapes from the openvdb site, for instance icosahedron and run:

1
vdb_view icosahedron.vdb

The result should look like on the figure below:

Then you may run tests (it takes a lot of time so I would skip it). When I did it, I found a error (testIO) which leads to program termination. The problem is in cpp-unit I use (1.12.1), to fix it comment call of CPPUNIT_ASSERT_NO_THROW in the TestCoord.cc lines 120 and 123. When you will try to use your openvdb library you may have problem: dyld cannot find an image. To fix this problem you may write export DYLD_LIBRARY_PATH=$DYLD_LIBRARY_PATH:<path_to_your_openvdb_lib>.