Difference between revisions of "Install (MinGW)"

From Open Babel
Jump to: navigation, search
m
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: March 31, 2009, Andreas Maunz. Tested with OB 2.1.1 on Windows Vista.
  
Using these instructions you'll be able to build and install libraries, includes, babel.exe and all the tests except unitcell.exe and smarttest.exe.
+
== Preliminaries: ==
 +
OpenBabel requires libxml2 so make sure you have this library properly installed in your MinGW environment; 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:
 +
<pre>
 +
    --cflags)
 +
        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>
  
0) OpenBabel requires libxml2 so make sure you have this library properly installed in your MinGW environment; libxml can be found here:
+
[http://www.mingw.org/wiki/Getting_Started, Install] current Msys and MinGW version.
  http://xmlsoft.org/
+
  
If you try to build OpenBabel 2.0.1 on Windows with MinGW you should
+
[http://sourceforge.net/project/showfiles.php?group_id=2435&package_id=241304 Update] to the latest version of g++ for MinGW (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, unpack OB source, start Msys and change to OB directory.
get something similar to the following:
+
  
 +
== Build OB: ==
 
<pre>
 
<pre>
./configure
+
./configure --without-boost --disable-dynamic-modules CXX=g++-sjlj
...
+
cd src/formats/inchi
 
make
 
make
...
+
cd ../../../tools
../../src/obutil.h:73: error: `gettimeofday' undeclared (first use
+
this function)
+
 
</pre>
 
</pre>
  
The compiler is complaining about a missing function; gettimeofday is in fact missing in a MinGW environment.
+
Edit the Makefile and exchange the following lines
  
To fix this you can do the following:
 
 
1) Open src/babelconfig.h.in
 
2) Add the followfing declaration:
 
  void gettimeofday( struct timeval* p, void* );
 
 
If you build now you get a brand new error message:
 
 
  bondtyper.cpp:21: bondtyp.h: No such file or director
 
 
The problem is that there are a number of files in the data dir which need
 
to be accessible and they are not because this directory is not in the include
 
path, here is part of the gcc command line you get:
 
 
  -I. -I. -I. -I../data
 
 
To fix this problem you need to add the data dir (where the bondtyp.h resides)
 
to the include path:
 
 
4) before running ./configure set the CPPFLAGS evironment variable:
 
  export CPPFLAGS="-I <absolute path to data dir>"
 
 
Now everything compiles but doesn't link yet because there is no definition
 
of function gettimeofday so in case you try to link you get the following
 
error:
 
 
  undefined reference to `gettimeofday(timeval*, void* )
 
 
We need to write the definition of this function in a c++ file and then
 
modify the makefile to include this new source file.
 
 
5) create a file gettimeofday.cpp and add the following code into it:
 
  (this is a version of some code I found on the internet a while ago)
 
 
 
 
<pre>
 
<pre>
  #include <windows.h>
+
babel_DEPENDENCIES = ../src/libopenbabel.la
  #include <sys/time.h>
+
babel_LDADD = ../src/libopenbabel.la
 +
</pre>
  
  void __stdcall GetSystemTimeAsFileTime(FILETIME*);
+
with
  
  void gettimeofday(struct timeval* p, void* tz /* IGNORED */)
 
  {
 
          union {
 
            long long ns100; /*time since 1 Jan 1601 in 100ns units */
 
                FILETIME ft;
 
          } now;
 
 
      GetSystemTimeAsFileTime( &(now.ft) );
 
      p->tv_usec=(long)((now.ns100 / 10LL) % 1000000LL );
 
      p->tv_sec= (long)((now.ns100-(116444736000000000LL))/10000000LL);
 
  }
 
</pre>
 
 
6) Modify Makefile.in adding gettimeofday.cpp to the list of source files:
 
  ...
 
 
<pre>
 
<pre>
  @[email protected] fingerprints/libfingerprints.la @[email protected]
+
babel_DEPENDENCIES = ../src/libopenbabel.la $(formats_objects)
  am__libopenbabel_la_SOURCES_DIST = gettimeofday.cpp atom.cpp
+
babel_LDADD = ../src/libopenbabel.la $(formats_objects)
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 \
+
  ...
+
 
</pre>
 
</pre>
  
If you build it with the current configuration you will incur in another
+
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 will be as well as the DLL will be placed in /local/bin (C:\Msys\local\bin).
problem: the dynamic library handler is set to unix
+
 
+
7a) substitute all the instances of dlhandler_unix.xxx in Makefile.in with
+
    dlhandler_win32.xxx, there should be a total of five occurrences
+
in the file.
+
    The use of a dynamic library handler should be automatically enabled when
+
    shared library support is turned on (default).
+
 
+
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 in Makefile.in
+
 
+
 
+
8) run configure --prefix=<installation folder> then make: this will build the
+
  libraries into src/.libs, you can then run make install
+
  installing for example into /c/local/test creates the following dir tree:
+
  
 
<pre>
 
<pre>
/c/local/test:
+
cd ..
bin
+
make
include
+
make install
lib
+
share
+
 
+
/c/local/test/bin:
+
babel.exe
+
libinchi-0.dll
+
libopenbabel-1.dll
+
 
+
/c/local/test/include:
+
inchi
+
openbabel-2.0
+
 
+
/c/local/test/include/inchi:
+
inchi_api.h
+
 
+
/c/local/test/include/openbabel-2.0:
+
openbabel
+
 
+
/c/local/test/include/openbabel-2.0/openbabel:
+
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:
+
matrix3x3.h
+
vector3.h
+
 
+
/c/local/test/lib:
+
libinchi.a
+
libinchi.dll.a
+
libinchi.la
+
libopenbabel.a
+
libopenbabel.dll.a
+
libopenbabel.la
+
openbabel
+
 
+
/c/local/test/lib/openbabel:
+
 
+
/c/local/test/share:
+
openbabel
+
 
+
/c/local/test/share/openbabel:
+
2.0.1
+
 
+
/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
+
 
</pre>
 
</pre>
  
 
[[Category:Installation]]
 
[[Category:Installation]]
 +
--[[User:Amaunz|Amaunz]] 07:18, 31 March 2009 (PDT)

Revision as of 06:18, 31 March 2009

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: March 31, 2009, Andreas Maunz. Tested with OB 2.1.1 on Windows Vista.

Preliminaries:

OpenBabel requires libxml2 so make sure you have this library properly installed in your MinGW environment; 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

Install current Msys and MinGW version.

Update to the latest version of g++ for MinGW (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, unpack OB source, start Msys and change to OB directory.

Build OB:

./configure --without-boost --disable-dynamic-modules CXX=g++-sjlj
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 will be as well as the DLL will be placed in /local/bin (C:\Msys\local\bin).

cd ..
make
make install

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