Hello all! I thought I’d post my notes I made a while back which helped me setup OpenVDB on Windows based systems using VS in case anyone finds it useful.
Step by step, compiling openVDB and the openVDB Viewer V(2.1) on Windows 7 under x86/64 for MT/MTd using the VC++10/11 for VS2010/2012. There’s not much that differs from Joe Kider’s post for openVDB 0.96.0 here https://groups.google.com/forum/#!topic/openvdb-forum/ZTEbIAk9kdc. However I’ve quickly expanded below on the setup of the prerequisites for anyone that needs it.
Prerequisites for core OpenVDB
We’ll be building all these libraries from source using the pre-set project folders for VS included with the downloads. You’ll need the following for the main source. Keep in mind we’re building for static linking:
- Boost, Download latest libs http://www.boost.org/users/download/
- zlib (and the zlib obj files)
- OpenEXR’s Half class from IlmBase V1.0.3. You can opt to only download this or build the complete OpenEXR lib if you don’t already have it
- 1a) Download zlib source (Tested with V1.25) and the zlib assembly code for 32 or 64bit http://www.winimage.com/zLibDll/index.html if you don’t have MASM.
- 1b) Copy the folder extracted from the assembly source called contrib. Paste this into the extract zlib source zlib-1.2.5 and confirm all merge prompts with the existing folders. Alternatively manually copy the obj files; navigate to the extracted folder from zlib124_masm_obj\contrib\masmx86 for 32 or masmx64 for 64. Copy both obj files. Paste them into the zlib source under zlib-1.2.5\contrib\masm x86/x64
- 1c) Go to the VS proj folder zlib-1.2.5\contrib\vstudio\vc10. Open up the solution. The proj you are after is the static lib (zlibstat), build with your required architecture and config (release/debug).
- 2a) If you only wish to build the Half class which is needed as a minimum, download IlmBase from OpenEXRs source (Tested V1.0.3) here http://www.openexr.com/downloads.html
- 2b) Navigate to the extracted folder\vc\vc9 and open the solution. Follow the prompts to convert the project (select no when asked to create a backup)
- 2c) The post build events for these projects assume you’re building the complete OpenEXR package and will create the deploy folder 2 directories up of your extracted location. You could just remove this step, however the folder structure it creates becomes much easier for include/lib paths later on. However if you wish to, just right click on each project in turn, > Properties > Build Events > Post-Build Event and removing the install command (install<projName>.cmd $(IntDir)).
- 2d) Build the Half project with your required architecture and config. If building in debug you may have to init the build twice for symbols.
- 3a) Download TBB source (Tested with V4.2 u2 – tbb42_20131118oss) https://www.threadingbuildingblocks.org/download
- 3b) Navigate to the extracted folder\build\vs2010, open the solution and build with your required arch. NOTE: I seem to get some redefinition errors for malloc and free later even by switching the code generation to MT and removing the cmd line overwrite, but currently just forcing multiple links later or choosing to remove defaultlib msvcrt.
Prerequisites for OpenVDB Viewer
For the viewer you’ll be needing glew and GLFW (glu as well but this should be standard). If you’re not actually looking to include to the viewer in the static lib just skip these.
- 4a) If somehow you don’t already have glew, download the source from http://glew.sourceforge.net/
- 4b) Navigate to build\vc10 and open and build the solutions static and shared libs.
- 5a) OpenVDB uses an older version of GLFW, as far as I know any version 2.x will work and is much easier to include that to try and update to 3.x. Download from https://github.com/glfw/glfw-legacy
- 5b) Navigate to the extract folder\support\msvc100, open the solution and build with your required architecture and config
Now for building the libs. You can choose to build the viewer and main source separately if you really want and just force the linker to link to both (as we are going to have to do this anyway) but it’s nicer not to. For JUST openVDB it follows the same steps as posted here https://groups.google.com/forum/#!topic/openvdb-forum/ZTEbIAk9kdc so I’ll only touch on this briefly.
- 1a) Open a new instance of VS2010/12 and select a new project. Select a Win32 Console App (as it becomes easier to tweak), deselect ‘Create directory for solution’ and give it a name. Click Ok, then Next.
- 1b) For the settings, deselect precompiled header and select Static Library. Finish
- 2a) You’ll be wanting to add the files from io, math, metadata, tools, tree, utils and the root openvdb folder sources and headers
- 2b) add #define NOMINMAX in Coord.h and add #define ZLIB_WINAPI in Compression.cc
- 2c) If you have only compiled the required Half class from IlmBase, change the include path in Types.h from <OpenEXR/half.h> to <half.h> and include location of the file in step 3b.
- 3a) Go to the properties of the project and navigate to C/C++ > Code Generation and select MTd if building in Debug or MT for release.
- 3b) Navigate to C/C++ in the properties window. In the Additional Include Directories add paths to your downloaded prerequisite include locations; boost, zlib.h, half.h, TBB, openVDB
- 4) Build the solution with your required architecture and config, this should create the static library for OpenVDB.
You can test your build with the code examples here http://www.openvdb.org/documentation/codeExamples.html.
Now for the viewer. I spent a while trying to get it compiled on both 32 and 64 bit systems, but it seems all the type problems related to rendermodules have been fixed in the latest release (v2.1), making things much easier. Please post if there are any errors for either, I’ve tested a fair amount for the new version and everything seems to work nicely.
For a joint library follow all above steps for the main source up to 4 and add the viewer files into the project. If you want a separate library, open a new instance of VS2010/12, follow the steps above but only add the files in the viewer folder (skip above 2a and 4).
-1a) Remove all #include <GL/gl.h> and <GL/glu.h> found in ClipBox.h, Font.h, RenderModules.h, Camera.cc and Viewer.cc and replace with #include <GL/glew.h>
- 1b) There are two places glew needs to be initialized (due to the threading?), one is when the viewer gets initialized in Viewer.cc, the other for when the shaders are first compiled in Rendermodules setshader() although I just opted to add it to the constructor of the shader program. Add glewInit(); to line 180 in RenderModules.cc and to line 165 in Viewer.cc when init is called.
init(const std::string& progName, bool verbose)
- 1c) In the Additional Include Directories add paths to your downloaded prerequisite include locations;
boost, zlib.h, half.h, TBB, OpenVDB, as well as glew and GLFW.
-1d) Build for your requried arch. If you get an error about obj file size (C1128), try adding /bigobj to the cmd line options under C/C++
- 1a) Open a new instance of VS2010/12 and new project. Select a Win32 Console App. For the settings, deselect precompiled header and select Empty Project. Keep it selected on a console application.
- 1b) add the main.cc file for initializing the viewer found in openvdb\cmd\openvdb_view.
- 1c) C/C++ compiler options: Add include paths to a minimum of TBB, Half, openVDB and boost. Change code generation to /MTd for debug, /MT for release
- 1d) Linker options: Add the following libraries locations under Linker > General > Additional Library Directories. Also add the libraries themselves under Linker > Input > Additional Dependencies in this order (this in an example of linking to the debug libs):
At the end include the viewer library and, if you compiled separately, then the main lib.
-1e) Add /FORCE:MULTIPLE to the command line linker options under Linker > Command Line.
-1f) Build the solution with your required architecture and config creating the viewer executable.
-1g) If they aren’t in your environment path, you’ll want to copy the glew, TBB and half shared dlls to the executable directory found in their respective bin directories.
- 1h) Download one of the example .vdb files from the openVDB site (one of the smaller ones to test) and add the path location to Properties > Debugging > Command Arguments of the solution. You should be able to run and use the viewer! For 32bit compilers you will get an assertion failure for a subscript range but you can ignore this.