Difference between revisions of "Install (MinGW)"

From Open Babel
Jump to: navigation, search
 
 
(18 intermediate revisions by 5 users not shown)
Line 1: Line 1:
This is a description of how to build openbabel 2.0.x on Windows with [http://www.mingw.org/ MinGW], if you do not care about what's going on and why the following actions are required just go through the numbered list items (1 to 8) and skip the explanations.
+
This document contains instructions for building OpenBabel (OB) on Windows with [http://www.mingw.org/ MinGW]. The resulting DLL (libopenbabel-3.dll) may be linked directly from Windows applications compiled with MinGW, so there is no need to deal with (import) libraries created with Microsoft Visual C++. This is especially useful if your existing software uses a GNU make based build system. Binaries created with MinGW are native and do not need an emulation layer, such as [http://www.cygwin.com/ Cygwin].
  
This text was contributed by the [http://www.cscs.ch/molekel/ Molekel] project. In the future, it is intended that Open Babel will compile cleanly on MinGW cleanly.
+
Date: October, 1010, Tested with OB 2.2.99 on Windows XP.
  
Using these instructions you'll be able to build and install libraries,
+
= Current and Development versions =
includes, babel.exe and all the tests except unitcell.exe and smarttest.exe.
+
  
0) OpenBabel requires libxml2 so make sure you have this library properly
+
== Building OpenBabel 2.3.0 using CMake ==
  installed in your MinGW environment; libxml can be found here:
+
  http://xmlsoft.org/
+
  
If you try to build OpenBabel 2.0.1 on Windows with MinGW you should
+
Install CMake 2.6 or newer. Install MSYS/MinGW using the installer and make sure to install the c++ compiler and developement tools. Download and install the '''msys zlib-dev''' and '''libxml2-dev (optional)''' packages when using the "MSYS Makefiles" or the '''mingw32 zlib-dev''' package for "MinGW Makefiles".
get something similar to the following:
+
  
./configure
+
=== Shared Library Build ===
...
+
make
+
...
+
../../src/obutil.h:73: error: `gettimeofday' undeclared (first use
+
this function)
+
  
The compiler is complaining about a missing function; gettimeofday is in fact
+
In the MSYS command prompt:
missing in a MinGW environment.
+
  
To fix this you can do the following:
+
cmake -G "MSYS Makefiles" -DCMAKE_INSTALL_PREFIX=/where/to/install -DZLIB_INCLUDE_DIR=/include -DZLIB_LIBRARY=/lib/'''libz.dll.a''' -DLIBXML2_INCLUDE_DIR=/include -DLIBXML2_LIBRARIES=/lib/'''libxml2.dll.a''' ..
 +
make
 +
make install
  
1) Open src/babelconfig.h.in
+
=== "Static" Library Build ===
2) Add the followfing declaration:
+
  void gettimeofday( struct timeval* p, void* );
+
  
If you build now you get a brand new error message:
+
Executables created using this method '''depend''' on kernel32.dll and the native '''MSVCRT.dll'''. The kernel32.dll dependency is not an issue since this is available on all windows machines. The C runtime (MSVCRT.dll) would have to be included with your executable though. AFAIK, it is not possible to use the static version of the runtime library. However, the formats and other plugins will be inside the executable.
  
bondtyper.cpp:21: bondtyp.h: No such file or director
+
In the MSYS command prompt:
  
The problem is that there are a number of files in the data dir which need
+
cmake -G "'''MSYS''' Makefiles" '''-DBUILD_SHARED=OFF''' -DCMAKE_INSTALL_PREFIX=/where/to/install -DZLIB_INCLUDE_DIR=/include -DZLIB_LIBRARY=/lib/'''libz.a''' -DLIBXML2_INCLUDE_DIR=/include -DLIBXML2_LIBRARIES=/lib/'''libxml2.a''' ..
to be accessible and they are not because this directory is not in the include
+
make
path, here is part of the gcc command line you get:
+
make install
  
-I. -I. -I. -I../data
+
== Building OpenBabel 2.2.2 using CMake ==
  
To fix this problem you need to add the data dir (where the bondtyp.h resides)
+
=== Installing MinGW ===
to the include path:
+
  
4) before running ./configure set the CPPFLAGS evironment variable:
+
Install MinGW with gcc 4. I used the manual install since the automated installer only allowed me to install gcc 3.4.
  export CPPFLAGS="-I <absolute path to data dir>"
+
Regardless of the install method, make sure to have at least these packages installed (i.e. extracted) to ''C:/MinGW''
  
Now everything compiles but doesn't link yet because there is no definition
+
* MinGW Runtime (mingwrt-3.15.2-mingw32-dev.tar.gz)
of function gettimeofday so in case you try to link you get the following
+
* Windows 32 API (w32api-3.13-mingw32-dev-tar.gz)
error:
+
* GNU Binutils (binutils-2.19.1-mingw32-bin.tar.gz)
 +
* GCC 4 (gcc-core-4.4.0-mingw32-bin.tar.gz, gcc-core-4.4.0-mingw-dll.tar.gz, gcc-g++-4.4.0-mingw32-bin.tar.gz,
 +
gcc-g++-4.4.0-mingw32-dll.tar.gz, gmp-4.2.4-mingw32-dll.tar.gzi, mpfr-2.4.1-mingw32-dll.tar.gz)
  
undefined reference to `gettimeofday(timeval*, void* )
+
Install MSYS using the installer (MSYS-1.0.10.exe). Start the msys prompt using '''Start > Programs > MinGW > MSYS > msys'''
 +
and verify the g++ version.
  
We need to write the definition of this function in a c++ file and then
+
$ g++ -v
modify the makefile to include this new source file.
+
...
 +
gcc version 4.4.0 (GCC)
  
5) create a file gettimeofday.cpp and add the following code into it:
+
It is also possible to use the automated installer and only add the g++ 4.4 packages later. See the  
  (this is a version of some code I found on the internet a while ago)
+
[[http://www.mingw.org/ MinGW Website]] for more information.
  #include <windows.h>
+
  #include <sys/time.h>
+
  
  void __stdcall GetSystemTimeAsFileTime(FILETIME*);
+
Some tips:
  
  void gettimeofday(struct timeval* p, void* tz /* IGNORED */)
+
* work in your MinGW '''home directory'''. I tried to build from a /z/... drive and didn't have much success this way.
  {
+
* Using MinGW, make sure to '''link directly to the dll files'''
          union {
+
            long long ns100; /*time since 1 Jan 1601 in 100ns units */
+
                FILETIME ft;
+
          } now;
+
  
      GetSystemTimeAsFileTime( &(now.ft) );
+
=== Shared Library Build ===
      p->tv_usec=(long)((now.ns100 / 10LL) % 1000000LL );
+
      p->tv_sec= (long)((now.ns100-(116444736000000000LL))/10000000LL);
+
  }
+
  
6) Modify Makefile.in adding gettimeofday.cpp to the list of source files:
+
Install CMake 2.6, an installer for the latest version is available on the [[http://www.cmake.org/ CMake Website]] (note: this is the normal windows CMake installer, you can use it from the MSYS prompt. For cygwin, the cygwin cmake package is needed.)
  ...
+
  @[email protected] fingerprints/libfingerprints.la @[email protected]
+
  am__libopenbabel_la_SOURCES_DIST = gettimeofday.cpp atom.cpp
+
base.cpp bitvec.cpp \
+
  ...
+
  @[email protected]__objects_1 = dlhandler_unix.lo
+
  am_libopenbabel_la_OBJECTS = gettimeofday.lo base.lo bitvec.lo bond.lo \
+
  ...
+
  libopenbabel_la_SOURCES = \
+
                gettimeofday.cpp atom.cpp base.cpp bitvec.cpp bond.cpp \
+
  ...
+
  
If you build it with the current configuration you will incur in another
+
$ export PATH=$PATH:/c/Program\ Files/CMake\ 2.6/bin
problem: the dynamic library handler is set to unix
+
$ cd ~/openbabel-2-2-x
 +
$ mkdir build
 +
$ cd build
 +
$ cmake -G "MSYS Makefiles" -DCMAKE_INSTALL_PREFIX=install_dir -DZLIB_INCLUDE_DIR=../include -DZLIB_LIBRARY=../windows-vc2005/'''zlib1.dll'''  -DLIBXML2_INCLUDE_DIR=../include -DLIBXML2_LIBRARIES=../windows-vc2005/'''libxml2.dll''' ..
 +
$ make
 +
$ make install
 +
 +
All files should now be installed to '''~/openbabel-2-2-x/build/install_dir'''. However, you still need to copy '''zlib1.dll, iconv.dll  & libxml2.dll to .../install_dir/bin'''.
  
7a) substitute all the instances of dlhandler_unix.xxx in Makefile.in with
+
$ cp ../windows-vc2005/zlib1.dll install_dir/bin
    dlhandler_windows.xxx, there should be a total of five occurrences
+
$ cp ../windows-vc2005/libxml2.dll install_dir/bin
in the file.
+
$ cp ../windows-vc2005/iconv.dll install_dir/bin
    The use of a dynamic library handler should be automatically enabled when
+
$ export PATH=$PATH:install_dir/bin
    shared library support is turned on (default).
+
$ babel -H
 +
...
  
7b) in case dlhandler is set to null in Makefile you'll have to manually remove
 
    @[email protected] in front of am_objects_1 and dlhandler =
 
dlhandler_win32.cpp
 
  
 +
= Old releases =
  
8) run configure --prefix=<installation folder> then make: this will build the
+
Date: March 31, 2009, Tested with OB 2.1.1 and 2.2.1 on Windows Vista.
  libraries into src/.libs, you can then run make install
+
  installing for example into /c/local/test creates the following dir tree:
+
  
/c/local/test:
+
== Preliminaries: ==
bin
+
OB requires libxml2; libxml can be found [http://xmlsoft.org/, here]. Specifically, this requires you to edit the xml2-config script. I recommend you directly link a test application against libxml2.dll and insert the respective -I and -L flags into xml2-config. The relevant section of mine looks like this:
include
+
<pre>
lib
+
    --cflags)
share
+
        echo -I/home/libxml2-2.7.3.win32/include/libxml -I/home/libxml2-2.7.3.win32/include
 +
</pre>
 +
and
 +
<pre>
 +
    --libs)
 +
        echo /c/Windows/System32/libxml2.dll -liconv -lm -Wl,-s -lwsock32 -liberty
 +
</pre>
  
/c/local/test/bin:
+
OB requires zlib; zlib can be found [http://gnuwin32.sourceforge.net/packages/zlib.htm here]. Make sure OB can find the header files and DLL during configuration by prior adding the respective directories to your $PATH environment variable.
babel.exe
+
libinchi-0.dll
+
libopenbabel-1.dll
+
  
/c/local/test/include:
+
[http://www.mingw.org/wiki/Getting_Started Install] current Msys and MinGW version. Unpack OB source, start Msys and change to OB directory. '''Warning:''' I experienced "object name conflicts" during compilation when the $PATH contained the windows\system32 directory at the beginning.
inchi
+
openbabel-2.0
+
  
/c/local/test/include/inchi:
+
== Build OB 2.2.1: ==
inchi_api.h
+
[http://sourceforge.net/project/showfiles.php?group_id=2435&package_id=241304 Update] the g++ compiler to version 4 (g++-sjlj, see also the [http://downloads.sourceforge.net/mingw/gcc-4.2.1-sjlj-2-release_notes.txt?use_mirror=freefr release notes]). Unpack gcc-g++-4.2.1-sjlj-2.tar.gz and gcc-core-4.2.1-sjlj-2.tar.gz in your MinGW root directory
  
/c/local/test/include/openbabel-2.0:
+
<pre>
openbabel
+
./configure CXX=g++-sjlj
 +
</pre>
 +
You may want to leave out boost and/or loading of dynamic modules by adding this to the configure command: <code>--without-boost --disable-dynamic-modules</code>.
 +
<pre>
 +
make
 +
</pre>
 +
Compilation of libopenbabel-3.dll breaks due to missing zlib support. You may manually fix this by repeating the last failed command and adding the file path to <code>zlib.dll</code>.  
  
/c/local/test/include/openbabel-2.0/openbabel:
+
--[[User:Amaunz|Amaunz]] 07:18, 31 March 2009 (PDT)
babelconfig.h
+
base.h
+
bitvec.h
+
bondtyper.h
+
chains.h
+
chiral.h
+
data.h
+
dlhandler.h
+
fingerprint.h
+
generic.h
+
grid.h
+
inchi_api.h
+
math
+
matrix.h
+
mol.h
+
molchrg.h
+
obconversion.h
+
oberror.h
+
obiter.h
+
obmolecformat.h
+
obutil.h
+
parsmart.h
+
patty.h
+
phmodel.h
+
reaction.h
+
ring.h
+
rotamer.h
+
rotor.h
+
typer.h
+
  
/c/local/test/include/openbabel-2.0/openbabel/math:
+
== Build OB 2.1.1: ==
matrix3x3.h
+
<pre>
vector3.h
+
./configure
 +
</pre>
 +
You may want to leave out boost and/or loading of dynamic modules: <code>./configure --without-boost --disable-dynamic-modules</code>.
 +
<pre>
 +
cd src/formats/inchi
 +
make
 +
cd ../../../tools
 +
</pre>
  
/c/local/test/lib:
+
Edit the Makefile and exchange the following lines
libinchi.a
+
libinchi.dll.a
+
libinchi.la
+
libopenbabel.a
+
libopenbabel.dll.a
+
libopenbabel.la
+
openbabel
+
  
/c/local/test/lib/openbabel:
+
<pre>
 +
babel_DEPENDENCIES = ../src/libopenbabel.la
 +
babel_LDADD = ../src/libopenbabel.la
 +
</pre>
  
/c/local/test/share:
+
with
openbabel
+
  
/c/local/test/share/openbabel:
+
<pre>
2.0.1
+
babel_DEPENDENCIES = ../src/libopenbabel.la $(formats_objects)
 +
babel_LDADD = ../src/libopenbabel.la $(formats_objects)
 +
</pre>
 +
 
 +
Repeat the editing for the rest of the executables if you need more than babel.exe. Then continue to build and install OB. The tools as well as the DLL will be placed in /local/bin (C:\Msys\local\bin).
 +
 
 +
<pre>
 +
cd ..
 +
make
 +
make install
 +
</pre>
  
/c/local/test/share/openbabel/2.0.1:
 
SMARTS_InteLigand.txt
 
aromatic.txt
 
atomtyp.txt
 
bondtyp.txt
 
element.txt
 
isotope-small.txt
 
isotope.txt
 
patterns.txt
 
phmodel.txt
 
resdata.txt
 
torlib.txt
 
types.txt
 
  
 
[[Category:Installation]]
 
[[Category:Installation]]

Latest revision as of 16:33, 12 October 2010

This document contains instructions for building OpenBabel (OB) on Windows with MinGW. The resulting DLL (libopenbabel-3.dll) may be linked directly from Windows applications compiled with MinGW, so there is no need to deal with (import) libraries created with Microsoft Visual C++. This is especially useful if your existing software uses a GNU make based build system. Binaries created with MinGW are native and do not need an emulation layer, such as Cygwin.

Date: October, 1010, Tested with OB 2.2.99 on Windows XP.

Current and Development versions

Building OpenBabel 2.3.0 using CMake

Install CMake 2.6 or newer. Install MSYS/MinGW using the installer and make sure to install the c++ compiler and developement tools. Download and install the msys zlib-dev and libxml2-dev (optional) packages when using the "MSYS Makefiles" or the mingw32 zlib-dev package for "MinGW Makefiles".

Shared Library Build

In the MSYS command prompt:

cmake -G "MSYS Makefiles" -DCMAKE_INSTALL_PREFIX=/where/to/install -DZLIB_INCLUDE_DIR=/include -DZLIB_LIBRARY=/lib/libz.dll.a -DLIBXML2_INCLUDE_DIR=/include -DLIBXML2_LIBRARIES=/lib/libxml2.dll.a ..
make
make install

"Static" Library Build

Executables created using this method depend on kernel32.dll and the native MSVCRT.dll. The kernel32.dll dependency is not an issue since this is available on all windows machines. The C runtime (MSVCRT.dll) would have to be included with your executable though. AFAIK, it is not possible to use the static version of the runtime library. However, the formats and other plugins will be inside the executable.

In the MSYS command prompt:

cmake -G "MSYS Makefiles" -DBUILD_SHARED=OFF -DCMAKE_INSTALL_PREFIX=/where/to/install -DZLIB_INCLUDE_DIR=/include -DZLIB_LIBRARY=/lib/libz.a -DLIBXML2_INCLUDE_DIR=/include -DLIBXML2_LIBRARIES=/lib/libxml2.a ..
make
make install

Building OpenBabel 2.2.2 using CMake

Installing MinGW

Install MinGW with gcc 4. I used the manual install since the automated installer only allowed me to install gcc 3.4. Regardless of the install method, make sure to have at least these packages installed (i.e. extracted) to C:/MinGW

  • MinGW Runtime (mingwrt-3.15.2-mingw32-dev.tar.gz)
  • Windows 32 API (w32api-3.13-mingw32-dev-tar.gz)
  • GNU Binutils (binutils-2.19.1-mingw32-bin.tar.gz)
  • GCC 4 (gcc-core-4.4.0-mingw32-bin.tar.gz, gcc-core-4.4.0-mingw-dll.tar.gz, gcc-g++-4.4.0-mingw32-bin.tar.gz,

gcc-g++-4.4.0-mingw32-dll.tar.gz, gmp-4.2.4-mingw32-dll.tar.gzi, mpfr-2.4.1-mingw32-dll.tar.gz)

Install MSYS using the installer (MSYS-1.0.10.exe). Start the msys prompt using Start > Programs > MinGW > MSYS > msys and verify the g++ version.

$ g++ -v
...
gcc version 4.4.0 (GCC)

It is also possible to use the automated installer and only add the g++ 4.4 packages later. See the [MinGW Website] for more information.

Some tips:

  • work in your MinGW home directory. I tried to build from a /z/... drive and didn't have much success this way.
  • Using MinGW, make sure to link directly to the dll files

Shared Library Build

Install CMake 2.6, an installer for the latest version is available on the [CMake Website] (note: this is the normal windows CMake installer, you can use it from the MSYS prompt. For cygwin, the cygwin cmake package is needed.)

$ export PATH=$PATH:/c/Program\ Files/CMake\ 2.6/bin
$ cd ~/openbabel-2-2-x
$ mkdir build
$ cd build
$ cmake -G "MSYS Makefiles" -DCMAKE_INSTALL_PREFIX=install_dir -DZLIB_INCLUDE_DIR=../include -DZLIB_LIBRARY=../windows-vc2005/zlib1.dll  -DLIBXML2_INCLUDE_DIR=../include -DLIBXML2_LIBRARIES=../windows-vc2005/libxml2.dll ..
$ make 
$ make install

All files should now be installed to ~/openbabel-2-2-x/build/install_dir. However, you still need to copy zlib1.dll, iconv.dll & libxml2.dll to .../install_dir/bin.

$ cp ../windows-vc2005/zlib1.dll install_dir/bin
$ cp ../windows-vc2005/libxml2.dll install_dir/bin
$ cp ../windows-vc2005/iconv.dll install_dir/bin
$ export PATH=$PATH:install_dir/bin
$ babel -H
...


Old releases

Date: March 31, 2009, Tested with OB 2.1.1 and 2.2.1 on Windows Vista.

Preliminaries:

OB requires libxml2; libxml can be found here. Specifically, this requires you to edit the xml2-config script. I recommend you directly link a test application against libxml2.dll and insert the respective -I and -L flags into xml2-config. The relevant section of mine looks like this:

    --cflags)
        echo -I/home/libxml2-2.7.3.win32/include/libxml -I/home/libxml2-2.7.3.win32/include

and

    --libs)
        echo /c/Windows/System32/libxml2.dll -liconv -lm -Wl,-s -lwsock32 -liberty

OB requires zlib; zlib can be found here. Make sure OB can find the header files and DLL during configuration by prior adding the respective directories to your $PATH environment variable.

Install current Msys and MinGW version. Unpack OB source, start Msys and change to OB directory. Warning: I experienced "object name conflicts" during compilation when the $PATH contained the windows\system32 directory at the beginning.

Build OB 2.2.1:

Update the g++ compiler to version 4 (g++-sjlj, see also the release notes). Unpack gcc-g++-4.2.1-sjlj-2.tar.gz and gcc-core-4.2.1-sjlj-2.tar.gz in your MinGW root directory

./configure CXX=g++-sjlj

You may want to leave out boost and/or loading of dynamic modules by adding this to the configure command: --without-boost --disable-dynamic-modules.

make

Compilation of libopenbabel-3.dll breaks due to missing zlib support. You may manually fix this by repeating the last failed command and adding the file path to zlib.dll.

--Amaunz 07:18, 31 March 2009 (PDT)

Build OB 2.1.1:

./configure

You may want to leave out boost and/or loading of dynamic modules: ./configure --without-boost --disable-dynamic-modules.

cd src/formats/inchi
make
cd ../../../tools

Edit the Makefile and exchange the following lines

babel_DEPENDENCIES = ../src/libopenbabel.la
babel_LDADD = ../src/libopenbabel.la

with

babel_DEPENDENCIES = ../src/libopenbabel.la $(formats_objects)
babel_LDADD = ../src/libopenbabel.la $(formats_objects)

Repeat the editing for the rest of the executables if you need more than babel.exe. Then continue to build and install OB. The tools as well as the DLL will be placed in /local/bin (C:\Msys\local\bin).

cd ..
make
make install