How I compiled OpenVDB Version 0.96.0 on Windows 7 using Visual Studio 2010

3,935 views
Skip to first unread message

Joe

unread,
Oct 24, 2012, 12:19:20 PM10/24/12
to openvd...@googlegroups.com
I thought this might be a useful tutorial since it took me an hour to figure out at first, and might save others time since it was not explicit in the download or forum to date.

This is how I compiled OpenVDB Version 0.96.0 on Windows 7 using Visual Studio 2010:

1) First download / compile for windows the requirements specified in the INSTALL file boost, libz, OpenEXR, TBB, etc..
( a bit overkill but if you ever wanted http://stackoverflow.com/questions/2629421/how-to-use-boost-in-visual-studio-2010 )
This is straight forward since google helps a lot, but I can always provide more details.

2) Open Visual Studio 2010
- File -> New Project   I just choose the Win32 Console Application and modified it later.
- Enter your project name (OpenVDB) and location of choice
- Hit Next
- Select : Static Library , Empty Project, and uncheck precompiled header

- Next dump the files in that you need (I kept the directories neat, but initially I just dumped everything in to test)
but you need to dump the root files Exceptions.h, Grid.cc, Grid.h ...
and the files from io, math, metadata, tools, tree, utils  (which are clear from line 161 of the MAKEFILE)
which files for what you need.

3) I had to add few lines to combat compile and linking errors on Windows.
a )  in Compression.cc   I added :
 #define ZLIB_WINAPI    
to the top of the file.
I got that information from this reference: http://www.winimage.com/zLibDll/index.html
"Make sure to define ZLIB_WINAPI before including zlib.h. Read contrib\vstudio\readme.txt file whithin zlib123.zip for more information."

b) in Coord.h   I added:
#define NOMINMAX
so that windows would not get confused.

(I put #ifdefines on these two and made my own #define for Windows, more optional but if you wanted to use the same based for windows and linux)

c) changing the /MDd to /MTd setting in C++/Code Generation  (or MT if in build not debug)
Right click the project under the solution in the "solution explorer" -> C/C++ -> Code Generation -> Runtime Library  : change to /MTd or /MT

d) in C/C++ -> General -> Additional Include Directories : I added my path to the needed includes from the INSTALL
Zlib, TBB, boost, openexr, openVDB (where your library code sits)

All should be well

=> F7 (BUILD Solution)

and it should generate OpenVDB.lib for you in your release or debug folder



Now next you want to test the Hello World program provided here :  http://www.openvdb.org/documentation/codeExamples.html

1) Open Visual Studio 2010
- File -> New Project   I just choose the Win32 Console Application and modified it later.
- Enter your project name (OpenVDB_Hello_World) and location of choice
- Hit Next
- Select : , Empty Project, and uncheck precompiled header

2) Project -> add new item - > C++ file 
Name it what you like

Copy the code from the example (making sure to wrap it in a   main()  function somewhere and add #include <iostream> so its a complete example.

3)  Edit your project settings again:

a) Right click the project under the solution in the "solution explorer" ->C/C++ -> Additional Include Directories
I added the paths again to the includes for Zlib, TBB, boost, openexr, openVDB (where your library code sits) like before
I just copied this line from the library project.

b) Code Generation must match /MTd or / MT  like above

c) under Linker -> input
I added Half.lib;OpenVDB.lib;zlibstat.lib;   to Additional Dependencies 
under Linker -> General-> Additional Library Directories
Add paths to the lib paths for
OpenEXR, TBB, OpenVDB ( lib project directory), zlib

Compile and run this project and you should generate the image below:


Best of luck.


Tonight I will try out 0.97.0 and let you know if that works out fine.

Dave

unread,
Oct 31, 2012, 12:45:23 PM10/31/12
to openvd...@googlegroups.com
Thanks Joe,

       Are you compiling and linking static libs or using dlls? I am having some issues with static libs using version 0.97.0. Things seem to be geared towards dlls by default. 

Dave  

Dave

unread,
Oct 31, 2012, 12:53:11 PM10/31/12
to openvd...@googlegroups.com
Joe,

   Sorry. I now see from your post that you are in fact linking to a static lib of OpenVDB. Did you need to change anything in Platform.h or any other headers to get this to work properly? Thanks.

Dave

Joe Kider

unread,
Oct 31, 2012, 1:00:01 PM10/31/12
to openvd...@googlegroups.com
Static,

no real changes to platform.h,  what was your error?

Dave

unread,
Oct 31, 2012, 6:12:57 PM10/31/12
to openvd...@googlegroups.com
Joe,

  The first error is below with similar ones for the other static member variables defined. 
  
 error C2491: 'openvdb::v0_97_0::io::Archive::sFormatVersionIndex' : definition of dllimport static data member not allowed C:\Code\hfWorkstationResearch\3rdParty\openvdb\io\Archive.cc Line 52

 It looks like if I add the _WIN32 preprocessor to my properties and undef _DLL in Platform.h I can work around this. 

ch...@nightmare-vfx.com

unread,
Aug 23, 2013, 7:29:46 PM8/23/13
to openvd...@googlegroups.com
I know this is a fairly old thread but I was just following it with 1.2.1.  Everything compiles without errors but when I try to run the program I get complaints that:

This version of c:\temp\hello.exe is not compatible with the version of Windows you're running. Check your computer's system information to see whether you need a x86 (32-bit) or x64 (64-bit) version of the program, and then contact the software publisher.

It was set for release/x64.  All includes/libraries that have x64 flavors are the ones it is including/linking.

Can anyone thing of anything I could be missing?

Ken Museth

unread,
Aug 24, 2013, 8:42:49 PM8/24/13
to openvd...@googlegroups.com
Hi Chris - have you tried the development version in GitHub (https://github.com/dreamworksanimation/openvdb_dev)? I know Edward (from SideFX), added several changes specifically to support Windows...

ch...@nightmare-vfx.com

unread,
Aug 24, 2013, 11:08:08 PM8/24/13
to openvd...@googlegroups.com
I don't think so.  Actually the issue I posted about is now gone and I'm running into linking issues.  I attribute most of that to the fact I have no idea what I'm doing.  :)   Will check out the Github version.  Thanks.

Ram Sampath

unread,
Sep 27, 2013, 9:06:30 PM9/27/13
to openvd...@googlegroups.com

Sorry I posted my reply to the author by mistake.

Anyway, here was my experience...


Although this might not be the case in your scenario..., here's one scenario in which linker errors could happen.

The TBB, boost libraries etc bundled with Houdini are compiled with Visual Studio 2008 and might not work if you link hello world in openvdb in Visual Studio 2010 or later.

Alternatively, downloading all the dependent libraries separately and compiling them using VS2010 or later should work...

Hope this helps.

Ram.

haggi

unread,
Oct 1, 2013, 5:44:57 PM10/1/13
to openvd...@googlegroups.com
I tried to compile VDB and now I have a lib, thanks for the description. But I have some problems with my test program. I get double defined symbols, but I don't know where the problem lies:

1>msvcprtd.lib(MSVCP100D.dll) : error LNK2005: "public: class std::basic_ostream<char,struct std::char_traits<char> > & __cdecl std::basic_ostream<char,struct std::char_traits<char> >::operator<<(float)" (??6?$basic_ostream@DU?$char_traits@D@std@@@std@@QEAAAEAV01@M@Z) already defined in OpenVDB.lib(openvdb.obj)
1>msvcprtd.lib(MSVCP100D.dll) : error LNK2005: "public: void __cdecl std::basic_ios<char,struct std::char_traits<char> >::setstate(int,bool)" (?setstate@?$basic_ios@DU?$char_traits@D@std@@@std@@QEAAXH_N@Z) already defined in VDBTestNeu.obj
1>msvcprtd.lib(MSVCP100D.dll) : error LNK2005: "public: __int64 __cdecl std::ios_base::width(__int64)" (?width@ios_base@std@@QEAA_J_J@Z) already defined in VDBTestNeu.obj
1>msvcprtd.lib(MSVCP100D.dll) : error LNK2005: "public: int __cdecl std::basic_streambuf<char,struct std::char_traits<char> >::sputc(char)" (?sputc@?$basic_streambuf@DU?$char_traits@D@std@@@std@@QEAAHD@Z) already defined in VDBTestNeu.obj
1>msvcprtd.lib(MSVCP100D.dll) : error LNK2005: "public: class std::basic_streambuf<char,struct std::char_traits<char> > * __cdecl std::basic_ios<char,struct std::char_traits<char> >::rdbuf(void)const " (?rdbuf@?$basic_ios@DU?$char_traits@D@std@@@std@@QEBAPEAV?$basic_streambuf@DU?$char_traits@D@std@@@2@XZ) already defined in VDBTestNeu.obj
1>msvcprtd.lib(MSVCP100D.dll) : error LNK2005: "public: char __cdecl std::basic_ios<char,struct std::char_traits<char> >::fill(void)const " (?fill@?$basic_ios@DU?$char_traits@D@std@@@std@@QEBADXZ) already defined in VDBTestNeu.obj
1>msvcprtd.lib(MSVCP100D.dll) : error LNK2005: "public: int __cdecl std::ios_base::flags(void)const " (?flags@ios_base@std@@QEBAHXZ) already defined in VDBTestNeu.obj
1>msvcprtd.lib(MSVCP100D.dll) : error LNK2005: "public: __int64 __cdecl std::ios_base::width(void)const " (?width@ios_base@std@@QEBA_JXZ) already defined in VDBTestNeu.obj
1>msvcprtd.lib(MSVCP100D.dll) : error LNK2005: "public: class std::basic_ostream<char,struct std::char_traits<char> > & __cdecl std::basic_ostream<char,struct std::char_traits<char> >::flush(void)" (?flush@?$basic_ostream@DU?$char_traits@D@std@@@std@@QEAAAEAV12@XZ) already defined in VDBTestNeu.obj
1>msvcprtd.lib(MSVCP100D.dll) : error LNK2005: "public: class std::basic_ostream<char,struct std::char_traits<char> > * __cdecl std::basic_ios<char,struct std::char_traits<char> >::tie(void)const " (?tie@?$basic_ios@DU?$char_traits@D@std@@@std@@QEBAPEAV?$basic_ostream@DU?$char_traits@D@std@@@2@XZ) already defined in VDBTestNeu.obj
1>msvcprtd.lib(MSVCP100D.dll) : error LNK2005: "public: bool __cdecl std::ios_base::good(void)const " (?good@ios_base@std@@QEBA_NXZ) already defined in VDBTestNeu.obj
1>msvcprtd.lib(MSVCP100D.dll) : error LNK2005: "public: void __cdecl std::basic_ostream<char,struct std::char_traits<char> >::_Osfx(void)" (?_Osfx@?$basic_ostream@DU?$char_traits@D@std@@@std@@QEAAXXZ) already defined in VDBTestNeu.obj
1>msvcprtd.lib(MSVCP100D.dll) : error LNK2005: "bool __cdecl std::uncaught_exception(void)" (?uncaught_exception@std@@YA_NXZ) already defined in libcpmtd.lib(uncaught.obj)

I use a static OpenVDB.lib and VS 2010 64bit. Any ideas?
Reply all
Reply to author
Forward
0 new messages