Building pbrt in VS 2005

By popular demand I'm posting a brief description of how I think I might have gotten pbrt to build in VS 2005. I'm very hesitant about many details, so feel free to add to or edit the contents of this page! Send questions and comments to <bergbom AT stanford DOT edu>.


For starters, pbrt doesn't seem to link well to the VS 2003 build of OpenEXR (differing runtime libs etc.), so a fresh build of this library is probably good. I finally ended up building in the Debug/Release modes, avoiding the DLL modes (which involve fixing and building createDLL).


Next, one needs to get the zlib stuff down, but I noticed that simply using the old build from the OpenEXR binary package works great (at least at link-time). So if you feel lazy, just copy the files as instructed in Readme.win32 (assuming OpenEXR\ is your OpenEXR source directory):


Never mind this library, unless you want the EXR Display app to work. In that case you're on your own.


OpenEXR include/lib

Once OpenEXR built, I copied the lib and include files from the OpenEXR build to replace the old ones in the OpenEXR subdir of the pbrt source. Note that I had to discard the new folder structure for the include files by manually moving the contents of Iex, IlmImf and Imath to the parent include folder. Also, as a heads-up the lib folder is actually called lib-win32, and finally the new lib folder doesn't contain zdll.lib so it has to be copied from the old one.

Building pbrt

Typically enough, this is where things get a bit diffuse. The things I remember doing are setting the /D "_CRT_SECURE_NO_DEPRECATE" flag in the 'core' project's C++ commandline to avoid a million warning messages, and setting the /NODEFAULTLIB:MSVCRT flag in 'core':s Linker Commandline. Much more than this shouldn't be necessary, unless I'm completely mistaken, in which case I recommend you read the last chapter.

One more thing I did, to facilitate later debugging, was to alter the target file in the debug build to 'pbrtd.exe' and replace the getenv line near line 56 in api.cpp with the following:

   1 #ifdef _DEBUG
   2         char *searchEnv = getenv("PBRT_SEARCHPATH_DEBUG");
   3 #else
   4         char *searchEnv = getenv("PBRT_SEARCHPATH");
   5 #endif

This in order to be able to call either one of the builds from any command line and having the correct DLLs loaded at runtime (provided the appropriate paths are added to the system's environment path).

Debugging pbrt

For debug purposes, you might want to run pbrt from within VS. To accomplish this, you need to set some debug variables. First of all, 'renderer' is the project that should be run, something you set in the Solution's properties. Furthermore, the following debug variables need to be set (in the 'renderer' project's properties):

Command: C:\libs\pbrt\src-1.02\win32\Projects\Debug\pbrtd.exe (adjust accordingly)
Command Arguments: the full path to your .pbrt file, eg: "C:\Documents and Settings\Mattias\My Documents\Classes\CS348\Homework1\config_5.pbrt" (including quotation marks)
Working Directory: the folder to your head_model.pbrt file, eg: "C:\Documents and Settings\Mattias\My Documents\Classes\CS348\Homework1" (including quotation marks, EXCLUDING trailing backslash)

Environment: PBRT_SEARCHPATH_DEBUG=$(TargetDir)

Note that for the Release settings, everything's similar except using Release\pbrt.exe and PBRT_SEARCH_PATH instead.

Still doesn't work?

Feel free to email me at <bergbom AT stanford DOT edu> and I'll try to recall if and how I solved whatever problem you're facing! With a little reminder I'm sure I'll be able to come up with something.

MattiasBergbom/vs2005pbrt (last edited 2006-04-12 06:15:53 by MattiasBergbom)