In this post I will describe a process of compiling Hello World example from OpenVDB library. I will take the first example from OpenVDB Cookbook. However instead of building the whole OpenVDB library I will take advantage of precompiled OpenVDB library shipping with Houdini. In this post I will assume that you have at least very basic understanding of compiling process.
Note, that Houdini does not have the latest version of OpenVDB. At the time of writing this post the latest OpenVDB version is 5.0.0, while Houdini 16.0.736 comes with 3.3.0. You can check your OpenVDB version in docs. OpenVDB version is not important for this simple example, so 3.3.0 will be fine, but compiling code using newer OpenVDB features will not work.
The first step is to check which g++ version is used in your system. Run in terminal:
$ g++ --version
It is important to use the same version of a compiler as the one Houdini was built with.
In my case I have Ubuntu with g++ 5.4.0 and I have installed this Houdini version: houdini-16.0.736-linux_x86_64_gcc4.8. This means trouble and the Hello World example will not compile with g++ 5.4.0. If your system is using g++ 4.8 then you are fine, if not then use your package manager to install required g++ (sudo apt install g++-4.8) and in following commands use g++-4.8 instead of g++.
Once your compiler is installed, create hello_world.cpp with the code from OpenVDB Cookbook.
There are more ways of compiling hello_world.cpp, I will show two of them.
Since we will be using Houdini libraries and headers we need to make our system environment aware of them. Fortunately there is an environment setup script coming with Houdini. It can be found in Houdini installation directory, in my case it is /opt/hfs16.0.736/. Change your working directory to it and run in terminal:
$ source houdini_setup
You should get message like this: The Houdini 16.0.736 environment has been initialized. This script initializes couple of variables which we will use and also adds Houdini binaries to PATH environment variable.
Compiling method one.
Houdini is coming with neat utility called hcustom. It is a tool made for simplifying process of compiling Houdini plugins (C++ libraries). However it is also capable of compiling standalone applications which is our case. You might need to install csh in order to use it in your system (sudo apt install csh). Hcustom has some neat options and can also take custom compiling flags. We need to add -DOPENVDB_3_ABI_COMPATIBLE in order to run the program (Houdini’s OpenVDB library was built with abi=3)
Execute following commands.
$ export HCUSTOM_CFLAGS="-DOPENVDB_3_ABI_COMPATIBLE" $ hcustom -i . -s -e -l tbb -l Half -l openvdb_sesi ./hello_world.cpp
Flag -s means to build a standalone application instead of building a library, -i points to target installation directory, -e means to show which commands are actually being executed, -l is pointing to the libraries required.
Also note, that hcustom by default uses g++ command, so you might need to point g++ in your environment to the correct version (g++-4.8).
Compiling method two.
$ g++ -DOPENVDB_3_ABI_COMPATIBLE -c -std=c++11 -isystem $HT/include -o hello_world.o hello_world.cpp $ g++ hello_world.o -L $HDSO -ltbb -lHalf -lopenvdb_sesi -o ./hello_world -Wl,-rpath,$HDSO
After that you should be able to run ./hello_world and get following result.
Testing random access: Grid[1000, -200000000, 30000000] = 1 Grid[1000, 200000000, -30000000] = 0 Testing sequential access: Grid[-2147483648, -2147483648, -2147483648] = 3 Grid[1000, -200000000, 30000000] = 1 Grid[1000, 200000000, -30000000] = 2 Grid[2147483647, 2147483647, 2147483647] = 4
Hope everything works well, if you have any suggestions/errors feel free to contact me 🙂