Binglong's space

Random notes on computer, phone, and life

Building OpenSceneGraph 3.0.0 from Source for Both x86 and x64

Posted by binglongx on July 27, 2011

In a previous post I talked about setup of using OpenSceneGraph (OSG) prebuilt binaries and briefly about building OSG from source.

There are occasions that one may want to build OSG from source. One of them is to gain the ability to debug into the source code of OSG when something is wrong.

The definite guide in building OSG from source is Getting Started, and specifically for Visual Studio on Windows.

The post here is complimentary to these guides, for building OSG on Windows with different versions and editions (x86/x64) of Visual Studio.


  • CMake 2.6+. OSG source code uses CMake to support multi-platform building. I use CMake 2.8.2.
  • Visual Studio. I use Visual Studio 2010 (VC++ 10).

Download and Organize OSG Files

  • Create an OSG version specific parent folder, e.g., d:\pub\OpenSceneGraph-3.0.0, for OSG 3.0.0. This folder, referred to as OSGV, will house: prebuilt 3rd party libraries, OSG source code, building intermediates, OSG installs.
  • Create folder <OSGV>\ThirdParty. This is the parent folder for all editions/versions of prebuilt 3rd party stuff. Do NOT use <OSGV>\3rdParty if you intend to use multiple configs, such as VC10_x86 and VC10_x64.
  • Download prebuilt 3rd party libraries:, or
  • Create folder <OSGV>\ThirdParty\VC10. This is the parent folder for 3rd party libraries.
  • Extract the 3rd party library files, such that <OSGV>\ThirdParty\VC10\x86 and <OSGV>\ThirdParty\VC10\x64 contains respectively 32-bit and 64-bit libraries. You should find bin, include, and lib directly under both folders. I merge the Debug and Release library files into the same folder; most of them are postfixed with “d” in Debug version.
  • Note: if you use exactly only one architecture, say VC10_x86, you can put its bin, include and lib directly under <OSGV>\3rdParty. <OSGV>\3rdParty is hardcoded in OSG CMake files, and it will automatically locate it and use it. Use <OSGV>\3rdParty only when you are using exactly one version/edition of Visual Studio. In that case, and you do not need to set OSG_3RDPARTY_DIR (skip that step, see below). Details of OSG CMake searching for 3rd party libraries can be found in <OSG>\CMakeModules\Find3rdPartyDependencies.cmake.
  • Create folder <OSGV>\OpenSceneGraph. This folder, referred to as OSG will contain the source code, for all builds such as VC10_x86 and VC10_x64.
  • Download source code of OSG and put it under <OSG>. If you use TortoiseSVN, you can right click the empty <OSG>, and check out Or, if you download the source code, extract the files here. In the end, you should see <OSG>\include and <OSG>\src.
  • Create folder <OSGV>\build. This is a parent folder is for the solutions, intermediate building files etc (out-of-source builds, in CMake terms).
  • Create folder <OSGV>\install. This is a parent folder is for built OSG files.

Generate Visual Studio Solution

  • Set environment variable OSG_3RDPARTY_DIR. The OSG CMake requires you to have this environment variable if the correct 3rd party libraries if there are multiple architectures/versions/editions. Since I am building for VC10, I set it to <OSGV>\ThirdParty\VC10. OSG CMake will find <OSGV>\ThirdParty\VC10\x86 or <OSGV>\ThirdParty\VC10\x64 correctly when you specify. Make sure there is no <OSGV>\3rdParty existing, or it would interfere with CMake.
  • Launch CMake, in Where is the source code, put in <OSG>.
  • In CMake, in Where to build the binaries, put in <OSGV>\build\VC10\x86, if you are building for VC10_x86. Put in <OSGV>\build\VC10\x64 if you are building VC10_x64.
  • In CMake, click “Configure”, then choose Visual Studio 10, and Use default native compilers. This assumes, running CMake in 32-bit Windows for 32-bit OSG builds, and in 64-bit Windows for 64-bit OSG builds. Wait for CMake to finish initial round of configuration.
  • Customize the build. In CMake, expand CMAKE, and change CMAKE_INSTALL_PREFIX to <OSGV>\install\VC10\Win32 (or <OSGV>\install\VC10\x64 for 64-bit build). All other default options should be good enough. Click “Congifure” again, when all red fields turn white, click “Generate” to generate the Visual Studio solution and project files.

Build OSG

  • Navigate to <OSGV>\build\VC10\x86, double click OpenSceneGraph.sln to open it in Visual Studio.
  • Build the solution for both Debug and Release. All the built DLLs, EXEs are generated in the corresponding build folder.
  • Build the INSTALL project in the solution. This will create bin, include, and lib sub-directories, and copy relevant files there, under CMAKE_INSTALL_PREFIX, i.e., <OSGV>\install\VC10\Win32 here.
  • If the 3rd party DLLs are going to be used, copy them to the appropriate sub-directory of the install directory. Because they are only used by plugins, put them under the plugin directory. For example, osgdb_tiff.dll plugin requires libtiff.dll, so copy <OSGV>\ThirdParty\VC10\x86\bin\libtiff.dll to <OSGV>\install\VC10\Win32\bin\osgPlugins-3.0.0. If you are unsure, use Dependency Walker to find out the DLL dependency.
  • Now the install directory (e.g., <OSGV>\build\VC10\Win32) is self-contained, meaning other projects using OSG only need to refer to this directory for all header files, library files and DLL files.
  • The build steps above can be repeated for VC10 x64 as well.

Setup Your Project to Use OSG

  • Set environment variable OSG_3_VC10_WIN32_ROOT to <OSGV>\install\VC10\Win32.
  • Follow the guidelines in the previous post’s Setup Your Project to Use OSG section.
  • Alternatively, take the platform out of the OSG root directory. Let environment variable OSG_3_VC10_ROOT point to <OSGV>\install\VC10, and in the Visual Studio project refer to the specific OSG installation folder through $(OSG_3_VC10_ROOT)\$(Platform). This makes your project uniform for both platforms.

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s


Get every new post delivered to your Inbox.

Join 52 other followers

%d bloggers like this: