Difference between revisions of "Compiling on Linux and Mac OS X"

From Avogadro - Free cross-platform molecule editor
Jump to: navigation, search
 
(51 intermediate revisions by 8 users not shown)
Line 1: Line 1:
These instructions are inteded to help users to build Avogadro from the latest code. Be aware that Avogadro may fail to build or work properly at any given time when built using the instructions below. <br/>
+
These instructions are intended to help users and contributors build Avogadro from the latest code. Be aware that Avogadro may fail to build or work properly at any given time when built using the instructions below. For the adventurous, there are also [[Compiling_on_Windows|Windows Visual Studio 2008]] instructions, although building on Windows is much more problematic.
For the adventurous, there are also [[Compiling_on_Windows|Windows Visual Studio 2008]] instructions that may or may not work.
 
  
Generally, users should first try the binary installers or packages available on the [[:Get_Avogadro|download]] page, made using a released version of Avogadro.
+
Generally, if you do not need the latest Avogadro features and are not interested in developing Avogadro, you should first try the binary installers or packages available on the [[:Get_Avogadro|download]] page. These are built using a released version of Avogadro which has received more testing than the current head of Git at any given moment.
 
 
Developers may want to use the instructions found at [[Building:Development_Version]].
 
  
  
 
== Dependencies ==
 
== Dependencies ==
 +
You should be able to find most of these dependencies in your distribution's repositories, or as binary downloads for Mac from the homepages linked below. Be careful to satisfy the version requirements.
  
;[http://subversion.tigris.org/ Subversion]
+
;[http://git-scm.com Git] (optional, but recommended)
;[http://git.or.cz/ Git]
+
;[http://www.cmake.org CMake] (>=2.6.0)
;[http://www.cmake.org CMake] (>=2.4.5)
+
;[http://qt.nokia.com/products/ Qt4] (>=4.6.x)
;[http://trolltech.com/products/qt Qt4] (>=4.4.0)
+
;[http://eigen.tuxfamily.org/ Eigen2] (>=2.0) (more instructions [[#Installing Eigen|below]])
;[[#Installing Eigen|Eigen]] (>=2.0_beta3)
+
;[http://openbabel.org/ OpenBabel] (>=2.3.0) (more instructions [[#Building OpenBabel|below]])
;[[#Building OpenBabel|OpenBabel]] (>=2.2.0)
 
  
It is likely that Subversion, Git, CMake and Qt4 will be available from your distribution's repositories, or in binary form on the Mac.
+
For the optional Python console/bindings:
 +
;[http://www.riverbankcomputing.co.uk/software/pyqt/download PyQt4]
 +
;[http://www.riverbankcomputing.co.uk/software/sip/download SIP]
 +
;[http://www.boost.org/users/download/ Boost]
  
 +
For optional OpenGL shader support:
 +
;[http://glew.sourceforge.net/ GLEW]
  
----
+
== Avogadro Squared ==
  
 +
If you have [http://git-scm.com Git] and [http://www.cmake.org/ CMake] installed, you can use the new "Avogadro Squared" build to fetch and build any needed dependencies.
  
There are two different ways to install Avogadro, depending on your needs and your user privileges.
+
  git clone --recursive git://github.com/cryos/avogadro-squared.git
 +
  mkdir avogadro-build
 +
  cd avogadro-build
 +
  cmake ../avogadro-squared
  
If you have superuser rights and want to provide Avogadro to all users on your computer, choose '''[[#Method A: Install Avogadro for all users|Method A]] to install Avogadro globally''' (to /usr/local).
+
== Installing Eigen2 ==
 +
You can obtain the [http://bitbucket.org/eigen/eigen/get/2.0.15.tar.bz2 Eigen2 source here].  
  
If you don't have superuser rights or you don't want to install files to locations outside your home directory or you're the only user of Avogadro, choose '''[[#Method B: Install Avogadro to your home diretory|Method B]] to install Avogadro into your home directory'''.
+
Assuming you have the sources, it can be build and installed as follows:
 
 
== Method A: Install Avogadro for all users ==
 
 
 
=== Installing Eigen ===
 
  
 
<code><pre>
 
<code><pre>
svn co svn://anonsvn.kde.org/home/kde/trunk/kdesupport/eigen2
 
 
cd eigen2
 
cd eigen2
mkdir build
+
mkdir $HOME/build/eigen2
cd build
+
cd $HOME/build/eigen2
cmake ..
+
cmake $HOME/src/eigen2
 +
make
 
sudo make install
 
sudo make install
 
</pre></code>
 
</pre></code>
  
=== Building Open Babel ===
+
'''Note:''' If you are either unable or do not want to install Eigen globally you can skip the final make install step.
Avogadro makes heavy use of code and features from the [http://openbabel.org Open Babel] chemistry toolbox. To ensure you have the latest Open Babel code you should build it from the code repository. It is sufficient to use OpenBabel 2.2.0 or more recent:
+
 
 +
== Building OpenBabel ==
 +
Avogadro makes heavy use of code and features from the [http://openbabel.org OpenBabel] chemistry toolbox. Avogadro needs OpenBabel 2.2.3 or more recent (preferably 2.3.0). If your distribution does not have a sufficiently recent version you may obtain it using:
  
 
<code><pre>
 
<code><pre>
svn co https://openbabel.svn.sourceforge.net/svnroot/openbabel/openbabel/trunk openbabel
+
cd $HOME/src
cd openbabel
+
svn co https://openbabel.svn.sourceforge.net/svnroot/openbabel/openbabel/branches/openbabel-2-3-x openbabel-2.3
 +
</pre></code>
 +
 
 +
Once you have the source code you can build it using:
 +
<code><pre>
 +
cd openbabel-2.3
 
./configure  
 
./configure  
make
+
make -j2
make install # must be run as root or with sudo
+
sudo make install
 
</pre></code>
 
</pre></code>
  
=== Building Avogadro ===
+
'''Note:''' If you are either unable or do not want to install OpenBabel globally you can skip the final make install step.
 +
 
 +
== Building Avogadro ==
  
Avogadro's version control system is now Git, with hosting provided by GitHub. If you would rather not install Git it is possible to download a tar or zip file containing the latest sources from [http://github.com/cryos/avogadro/ here] by clicking on the download link. Generally you will want to clone the git repository,
+
Avogadro uses Git for version control, with hosting provided by GitHub. If you would rather not install Git it is possible to download a tar or zip file containing the latest sources from [http://github.com/cryos/avogadro/ here]. Click on the download link, unpack the file and adjust the instructions as necessary. It is generally a good idea to clone the repository if you intend to contribute or regularly build the latest sources. For more details about Git and Avogadro please see [[Working_With_Git]].
  
 
<code><pre>
 
<code><pre>
 +
cd $HOME/src
 
git clone git://github.com/cryos/avogadro.git
 
git clone git://github.com/cryos/avogadro.git
cd avogadro
+
mkdir -p $HOME/build/avogadro
mkdir build
+
cd $HOME/build/avogadro
cd build
+
cmake $HOME/src/avogadro
cmake ..
+
make -j2
make -j3
 
 
sudo make install
 
sudo make install
 
</pre></code>
 
</pre></code>
  
=== Running ===
+
'''Note:''' If you are either unable or do not want to install Avogadro globally you can run in from your home directory using the following instructions. The instructions assume you have built Eigen and OpenBabel in your home directory too.
 +
 
 +
'''Setting up the environment'''
 +
 
 +
If you set these environment variables Avogadro and OpenBabel will use special directories for runtime plugin loading. Avogadro will search the subdirectories colors, engines, extensions and tools for suitable plugins. The environment variables can point to multiple directories separated by colons, i.e. "$HOME/.avogadro/plugins:/usr/local/lib/avogadro". All of them are optional, if they are installed then there is no need to set any environment variables.
 +
 
 +
<code><pre>export AVOGADRO_TRANSLATIONS=$HOME/build/avogadro/avogadro/src                                      #Avogadro Translations
 +
export BABEL_LIBDIR=$HOME/src/openbabel/src/formats/.libs:$HOME/src/openbabel/src/formats/xml/.libs  #Openbabel Formats
 +
export BABEL_DATADIR=$HOME/src/openbabel/data                                                        #Openbabel Data Files</pre></code>
 +
 
 +
'''Mac Specific Build Instructions'''
 +
 
 +
If you would like to create binaries that will work on both Tiger and Leopard with both x86 and ppc Macs then the CMakeCache.txt in the build directory must contain,
 +
 
 +
<pre>CMAKE_OSX_ARCHITECTURES:STRING=i386;ppc
 +
CMAKE_OSX_SYSROOT:PATH=/Developer/SDKs/MacOSX10.4u.sdk</pre>
 +
 
 +
You also need to export the environment variable to build for Tiger,
 +
 
 +
<pre>export MACOSX_DEPLOYMENT_TARGET=10.4</pre>
 +
 
 +
'''Building Avogadro'''
 +
 
 +
These instructions assume that the OpenBabel sources are compiled in your home directory but not installed.
 +
 
 +
<code><pre>
 +
cd $HOME/src
 +
git clone git://github.com/cryos/avogadro.git
 +
mkdir -p $HOME/build/avogadro
 +
cd $HOME/build/avogadro
 +
cmake \
 +
  -DOPENBABEL2_INCLUDE_DIR=$HOME/src/openbabel-2.2/include \
 +
  -DOPENBABEL2_LIBRARIES=$HOME/src/openbabel-2.2/src/.libs/libopenbabel.so \
 +
  -DOPENBABEL2_VERSION_MET=true $HOME/src/avogadro
 +
make -j2
 +
</pre></code>
 +
 
 +
'''Note:''' Since compilation of translation files for all languages takes noticeable time, you may speed up build by choosing only one localization. To do it, append <tt>-DI18N_LANGUAGE=your_language_code</tt> to cmake command, e.g., <tt>-DI18N_LANGUAGE=ru</tt>
 +
 
 +
'''Building Avogadro with Python Support'''
 +
 
 +
To be able to access the python terminal within Avogadro, you will need to have boost python, python libraries, python interpreter, the numpy module, and the SIP module already installed on your computer. If you have all the required dependencies, the output when running cmake should be like:
 +
 
 +
<code><pre>
 +
...
 +
-- [1/5] Boost Python
 +
-- Boost Python found...
 +
-- [2/5] Python Libraries
 +
-- Found PythonLibs: /usr/lib/libpython2.6.so
 +
-- [3/5] Python Interpreter
 +
-- Found PythonInterp: /usr/bin/python2.6
 +
-- [4/5] Numpy Module
 +
-- Numpy headers found
 +
-- [5/5] SIP Module
 +
-- Found sip.h header...
 +
-- using sip version 4.8 or above...
 +
-- All python dependencies found - Python support enabled
 +
...
 +
</pre></code>
 +
 
 +
To make sure that all the Python dependencies are fulfilled on Ubuntu you can use apt-get. Similar packages should be available from the repositories of other Linux flavors.
 +
 
 +
<code><pre>
 +
sudo apt-get install libboost-python-dev python-numpy-dev sip4
 +
</pre></code>
 +
 
 +
now all that is required is to run "make" and then "make install" according to the install instructions supplied with the source code. "make install" moves the Avogadro python module to the correct location. If you want to find the directory containing the python modules, you
 +
can always use this python script:
 +
 
 +
<code><pre>
 +
>>> from sys import stdout
 +
>>> from distutils import sysconfig
 +
>>> stdout.write(sysconfig.get_python_lib())
 +
</pre></code>
 +
 
 +
== Running ==
  
 
<code><pre>avogadro</pre></code>
 
<code><pre>avogadro</pre></code>
On Mac OS X Avogadro will be in your Applications folder.
+
On Linux, if you installed Avogadro globally and you had Avogadro previously installed from repositories, you may need to execute
 +
<code><pre>/usr/local/bin/avogadro</pre></code> to run new version. However, it's recommended to uninstall <tt>avogadro</tt> package before installation from sources to prevent collisions.
 +
On Mac OS X Avogadro will be in your Applications folder, or you can run it from the build directory inside the bin folder.
  
== Method B: Install Avogadro into your home diretory ==
+
'''Note:''' If you have built Avogadro using the directions in the previous section then run Avogadro using:
 +
<code><pre>$HOME/build/avogadro/bin/avogadro</pre></code>
  
[[Category:User]]
+
[[Category:User]] [[Category:Developer]]

Latest revision as of 08:54, 21 February 2012

These instructions are intended to help users and contributors build Avogadro from the latest code. Be aware that Avogadro may fail to build or work properly at any given time when built using the instructions below. For the adventurous, there are also Windows Visual Studio 2008 instructions, although building on Windows is much more problematic.

Generally, if you do not need the latest Avogadro features and are not interested in developing Avogadro, you should first try the binary installers or packages available on the download page. These are built using a released version of Avogadro which has received more testing than the current head of Git at any given moment.


Dependencies

You should be able to find most of these dependencies in your distribution's repositories, or as binary downloads for Mac from the homepages linked below. Be careful to satisfy the version requirements.

Git (optional, but recommended)
CMake (>=2.6.0)
Qt4 (>=4.6.x)
Eigen2 (>=2.0) (more instructions below)
OpenBabel (>=2.3.0) (more instructions below)

For the optional Python console/bindings:

PyQt4
SIP
Boost

For optional OpenGL shader support:

GLEW

Avogadro Squared

If you have Git and CMake installed, you can use the new "Avogadro Squared" build to fetch and build any needed dependencies.

 git clone --recursive git://github.com/cryos/avogadro-squared.git
 mkdir avogadro-build
 cd avogadro-build
 cmake ../avogadro-squared

Installing Eigen2

You can obtain the Eigen2 source here.

Assuming you have the sources, it can be build and installed as follows:

cd eigen2
mkdir $HOME/build/eigen2
cd $HOME/build/eigen2
cmake $HOME/src/eigen2
make
sudo make install

Note: If you are either unable or do not want to install Eigen globally you can skip the final make install step.

Building OpenBabel

Avogadro makes heavy use of code and features from the OpenBabel chemistry toolbox. Avogadro needs OpenBabel 2.2.3 or more recent (preferably 2.3.0). If your distribution does not have a sufficiently recent version you may obtain it using:

cd $HOME/src
svn co https://openbabel.svn.sourceforge.net/svnroot/openbabel/openbabel/branches/openbabel-2-3-x openbabel-2.3

Once you have the source code you can build it using:

cd openbabel-2.3
./configure 
make -j2
sudo make install

Note: If you are either unable or do not want to install OpenBabel globally you can skip the final make install step.

Building Avogadro

Avogadro uses Git for version control, with hosting provided by GitHub. If you would rather not install Git it is possible to download a tar or zip file containing the latest sources from here. Click on the download link, unpack the file and adjust the instructions as necessary. It is generally a good idea to clone the repository if you intend to contribute or regularly build the latest sources. For more details about Git and Avogadro please see Working_With_Git.

cd $HOME/src
git clone git://github.com/cryos/avogadro.git
mkdir -p $HOME/build/avogadro
cd $HOME/build/avogadro
cmake $HOME/src/avogadro
make -j2
sudo make install

Note: If you are either unable or do not want to install Avogadro globally you can run in from your home directory using the following instructions. The instructions assume you have built Eigen and OpenBabel in your home directory too.

Setting up the environment

If you set these environment variables Avogadro and OpenBabel will use special directories for runtime plugin loading. Avogadro will search the subdirectories colors, engines, extensions and tools for suitable plugins. The environment variables can point to multiple directories separated by colons, i.e. "$HOME/.avogadro/plugins:/usr/local/lib/avogadro". All of them are optional, if they are installed then there is no need to set any environment variables.

export AVOGADRO_TRANSLATIONS=$HOME/build/avogadro/avogadro/src                                       #Avogadro Translations
export BABEL_LIBDIR=$HOME/src/openbabel/src/formats/.libs:$HOME/src/openbabel/src/formats/xml/.libs  #Openbabel Formats
export BABEL_DATADIR=$HOME/src/openbabel/data                                                        #Openbabel Data Files

Mac Specific Build Instructions

If you would like to create binaries that will work on both Tiger and Leopard with both x86 and ppc Macs then the CMakeCache.txt in the build directory must contain,

CMAKE_OSX_ARCHITECTURES:STRING=i386;ppc
CMAKE_OSX_SYSROOT:PATH=/Developer/SDKs/MacOSX10.4u.sdk

You also need to export the environment variable to build for Tiger,

export MACOSX_DEPLOYMENT_TARGET=10.4

Building Avogadro

These instructions assume that the OpenBabel sources are compiled in your home directory but not installed.

cd $HOME/src
git clone git://github.com/cryos/avogadro.git
mkdir -p $HOME/build/avogadro
cd $HOME/build/avogadro
cmake \
  -DOPENBABEL2_INCLUDE_DIR=$HOME/src/openbabel-2.2/include \
  -DOPENBABEL2_LIBRARIES=$HOME/src/openbabel-2.2/src/.libs/libopenbabel.so \
  -DOPENBABEL2_VERSION_MET=true $HOME/src/avogadro
make -j2

Note: Since compilation of translation files for all languages takes noticeable time, you may speed up build by choosing only one localization. To do it, append -DI18N_LANGUAGE=your_language_code to cmake command, e.g., -DI18N_LANGUAGE=ru

Building Avogadro with Python Support

To be able to access the python terminal within Avogadro, you will need to have boost python, python libraries, python interpreter, the numpy module, and the SIP module already installed on your computer. If you have all the required dependencies, the output when running cmake should be like:

...
-- [1/5] Boost Python
-- Boost Python found...
-- [2/5] Python Libraries
-- Found PythonLibs: /usr/lib/libpython2.6.so
-- [3/5] Python Interpreter
-- Found PythonInterp: /usr/bin/python2.6
-- [4/5] Numpy Module
-- Numpy headers found
-- [5/5] SIP Module
-- Found sip.h header...
-- using sip version 4.8 or above...
-- All python dependencies found - Python support enabled
...

To make sure that all the Python dependencies are fulfilled on Ubuntu you can use apt-get. Similar packages should be available from the repositories of other Linux flavors.

sudo apt-get install libboost-python-dev python-numpy-dev sip4

now all that is required is to run "make" and then "make install" according to the install instructions supplied with the source code. "make install" moves the Avogadro python module to the correct location. If you want to find the directory containing the python modules, you can always use this python script:

>>> from sys import stdout
>>> from distutils import sysconfig
>>> stdout.write(sysconfig.get_python_lib())

Running

avogadro

On Linux, if you installed Avogadro globally and you had Avogadro previously installed from repositories, you may need to execute

/usr/local/bin/avogadro
to run new version. However, it's recommended to uninstall avogadro package before installation from sources to prevent collisions.

On Mac OS X Avogadro will be in your Applications folder, or you can run it from the build directory inside the bin folder.

Note: If you have built Avogadro using the directions in the previous section then run Avogadro using:

$HOME/build/avogadro/bin/avogadro