Here we describe how to compile OpenBabel on Windows using the Microsoft Visual C++ compiler (MSVC).
We recommend the following compiler which is available for free:
Microsoft would prefer you use the .NET framework, but they also support "native" code - it's just that they don't make it too easy.
You also need to install the Platform SDK to provide the Windows files. Don't be put off because it is called "Microsoft Platform SDK for Windows Server 2003 R2" Follow the instructions in . At Step 4 when updating the corewin_express.vsprops file, the list of libraries should be "kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib comctl32.lib rpcrt4.lib". Also just before this add a section:
<Tool Name="VCCLCompilerTool" PreprocessorDefinitions= "_CRT_SECURE_NO_DEPRECATE;_CRT_NONSTDC_NO_DEPRECATE;_CRT_SECURE_CPP_OVERLOAD_STANDARD_NAMES" />
This (usually) avoids warnings about unsafe functions like sprintf for which Microsoft have provided "safe" alternatives. Read a critique of these here. They are not usable in cross-platform code because they are non-standard. Ignore any such warnings that have failed to be supressed.
At Step 5 the line numbers now seem to be pp478-481.
OpenBabel source code
Although the source code package from the SourceForge download page has all the OpenBabel code, it may not have some of the ancillary files, since it is really intended for UNIX(Linux) systems. If you intend to compile under Windows it is much better to download the code from SVN. Tortoise SVN is a very convenient client for SVN - it operates from Windows explorer - and is easy to install. Then make a directory for the OpenBabel file, right click and select SVN Checkout. For a released version of OpenBabel enter something like:
or for the development code:
Click OK and all the code and required external DLLs (e.g. for InChI and libxml2) are downloaded.
You need to install some elements of the Boost Library. This is done as follows:
- Download and run the BoostPro 1.34.1 Installer
- Choose the Visual Studio 2005 version
- Choose both of the single thread variants
- On the next screen, choose just the Boost header files and deselect everything else
- Complete the installation
- Open windows-vc2005/openbabel.sln with Visual Studio and right-click on OpenBabelDLL, Properties, C/C++, Additional Include Directories and add C:\Program Files\boost\boost_1_34_1 (or whereever you installed Boost)
At this stage you should be able to compile the command-line version of OpenBabel. Open windows-vc2005/openbabel.sln and build the project OBComLn. (Do not build the whole solution.) OpenBabelDLL.dll, which contains most of OpenBabel is built first.
For v2.2 and later, OpenBabelOBF.sln contains an alternative build with the core as multiple DLLs and formats and extensions as plugin *.obf files. This allows the package to be expanded or slimmed after compilation by adding or removing obf files.
- Unzip it into a folder that doesn't contain spaces
- Read the install notes in the distribution
- Read more install notes on the web site
- Set the environment variable WXWIN to the installation directory of wxWidgets, e.g. E:\wxWidgets-2.8.3, and restart MSVC.
- In the file$(WXWIN)/include/wx/msw/setup.h change
#define wxUSE_STD_IOSTREAM 0
#define wxUSE_STD_IOSTREAM 1
- In the file $(WXWIN)/include/wx/msw/wx.rc find the section "Manifest file for Windows XP" and add immediately after it:
//For Visual Studio 2005 #define wxUSE_NO_MANIFEST 1 #if defined(__WXMSW__) && !defined(__WXWINCE__) #pragma comment(linker, "\"/manifestdependency:type='Win32' name='Microsoft.Windows.Common-Controls' version='126.96.36.199' processorArchitecture='X86' publicKeyToken='6595b64144ccf1df'\"") #endif //
This ensures that the latest version of Common Controls is used.
- Open "build\msw\wx.dsw" and answer "Yes to All" for the format conversion. (There is no need to save the converted project files.)
- On the menu, choose "Batch Build", and sort by "Configuration". Select only those configurations of type "Release" and, possibly "Debug", and click on Build All.
The GUI can be built by opening openbabel.sln and building the project OBGUII.
Debugging with Visual Studio
If you do a significant amount of debugging of OpenBabel code, you may wish to have the OpenBabel objects appear in the the Autos or Locals debugging windows in a more useful form. There is a lot that can be done but the simple suggestion here is a start.
Edit the file C:\Program Files\Microsoft Visual Studio 8\Common7\Packages\Debugger\autoexp.dat
In the [AutoExpand] section add the following text
; OpenBabel OpenBabel::OBMol =<_title> <_natoms> atoms, <_nbonds> bonds OpenBabel::OBAtom =index=<_idx> <_ele> charge=<_fcharge> wxString=<m_pchData,st>
and restart Visual Studio.
In the debugger OBMol, OBAtom and wxString objects will be easier to identify.