Compiling from Source

From TexGen
Revision as of 15:47, 2 November 2007 by Joncrookston (talk | contribs)
Jump to navigationJump to search

In order to compile TexGen and all of its modules, the following software is required:

The following programs are needed to build TexGen:

The following libraries are needed to link to TexGen:

However to perform a minimum build of TexGen with none of the additional modules you only require CMake and a C++ compiler. It is recommended to begin with a minimum build, once that is working try adding modules one at a time. A list of modules along with dependencies is shown below:

  • Python interface: Python, SWIG
  • Renderer: VTK
  • Export: OpenCascade
  • GUI: wxWidgets, Renderer, Python interface
  • Unit tests: CPPUnit

A graphical representation of the modules and their dependencies can also be found in the TexGen API.

If you want to get the source code from the Subversion repository you will need to install Subversion by following the instructions below. Note that this is the very latest development source and so may it contain some bugs and unfinished features. However it is very easy to keep up to date with the latest version of TexGen using this method and will allow you to keep any modifications you have made to the source when updating. If you find a bug or implement new features that may be usefull to the rest of the community they can also be submited as patch and incorporated into TexGen following review.

Alternatively the stable source code can be downloaded as a tarball. Download the latest file release named texgen-3.x.x.tar.gz.

Windows compile

Microsoft Visual Studio C++

(This section is currently being written)

Download and install Subversion

Download the Subversion installer from here, and run it. The installation process is straightforward.

Download and install the other packages required to compile TexGen

It is assumed that Microsoft Visual Studio is already installed. If it isn't and you plan to use it, then install it. It may be possible to use the free Visual Studio Express; if anyone tries this and finds out one way or the other, please post the information either here or in the forum. The other packages required are:

  1. Required:
  2. Optional, depending on which modules will be built:
    • Python - used for scripting (required for Python module) (download)
    • OpenCascade - used for geometry export (required for Export module) (download)
    • VTK - used for rendering (required for Renderer module) (download)
    • wxWidgets - used for handling the GUI (required for GUI module) (download)

(Note that the GUI module requires the Python, Renderer and Export modules.)

Notes:

CMake - download the installer and run, selecting 'Add CMake to the system PATH for all users' (select current user if this is not permissible on your system).

Python - if you wish to use TexGen Python scripting from within the Abaqus/CAE computer aided engineering environment, you must install the appropriate version of Python. Abaqus 6.6-1 uses Python 2.3.3; Abaqus 6.7-1 uses Python 2.4.3 (you can check this for your Abaqus installation by typing 'abaqus python -V'). If you don't require this type of functionality, the latest stable Python release is recommended. (Hint: specific releases can be downloaded from http://www.python.org/download/releases/x.y.z/ where x.y.z represents the version number.)

OpenCascade - Download the installer and run it; this extracts the files to a directory. If installation doesn't start automatically, run the 'install.bat' script which is in this directory, or look at the 'readme.htm' file in the same directory for more information. Choose 'complete installation' and tick the box to set the environment variables.

VTK - Download the installer and run. (Does this work, or is it necessary to compile VTK from source?)

wxWidgets - Download the windows installer (wxMSW) and run. It is necessary to compile wxWidgets. Do this by opening the Visual Studio project file (C:\Program Files\wxWidgets-2.8.6\build\msw\wx.dsw) and building both Release and Debug configurations (select the appropriate configuration from the drop down box on the main toolbar in Visual Studio).

SWIG - download the latest release of the windows .zip files and extract to a suitable location (e.g. c:\Program Files\swigwin-1.3.31). (Does this now need to be installed?)

Set up a subversion repository and download the TexGen source code

Create a directory where you would like to store the TexGen source code, e.g. C:\SVN\TexGen In Windows Explorer, right click on this folder. In the context menu which appears, choose 'SVN Checkout...'. In the dialogue which follows, in the URL field enter 'https://texgen.svn.sourceforge.net/svnroot/texgen/TexGen/trunk/'. The Checkout directory field should be the name of the directory where you plan to keep the code (c:\SVN\TexGen). Make sure that 'HEAD revision' is selected and click OK. The code will now be downloaded. From now on, the code in this folder can be updated using the 'SVN Update' context menu option.

Start compiling

First of all, copy the file 'FindwxWidgets.cmake' from 'C:\SVN\TexGen\GUI' to 'C:\Program Files\CMake 2.4\share\cmake-2.4\Modules'. This is necessary to help cmake find all of the wxWidgets modules.

Run CMake from its shortcut on the Start menu.

In the dialogue box, fill in the fields giving the location of the source code (C:\SVN\TexGen) and the destination (e.g. C:\Program Files\TexGen3.2.0), then click 'Configure'. Choose the Visual Studio version which you have installed and click 'OK'. Various amendments will be required, depending on your exact system configuration, hopefully most of them will be covered below:

CMake Error: Swig was not found on the system. Please specify the location of Swig. (click OK)

CMake Error: Error in configuration process, project files may be invalid. (click OK)

Now look at the 'Cache Values' in the CMake window. This is where we tell the computer which modules to build, by setting the values of the fields such as 'BUILD_GUI' etc. These simply toggle between OFF and ON.

There may be problems listed; in my test installation, the problems were with 'PYTHON_SITEPACKAGES_DIR' and 'SWIG_DIR' - their values both said 'NOTFOUND'. Click on the values and click the '...' button which appears to browse for the folders. The exact locations will depend on where Swig and Python were installed. In my case the values were 'C:\Program Files\Python24\Lib\site-packages' and 'C:\Program Files\swigwin-1.3.31' respectively. Set these and choose 'Configure' again.

CMake Error: wxWidgets required, please specify its location (click OK)

'wxWidgets_LIB_DIR' needs to be found and set. In my case it was 'C:\Program Files\wxWidgets-2.8.6\lib\vc_lib'. Click 'Configure' once again and, with any luck, there will be a message at the bottom to say 'Configuring done'.

In my case, 'BUILD_CASCADE_EXPORT' was set to 'OFF'. I changed it to 'ON' and 'Configure'd again. This results in:

CMake Error: This project required some variables to be set, and cmake can not find them. Please set the following variables:

OPENCASCADE_INCLUDE_DIR (click OK)

Looking at the Cache Values again, there are also a couple of other variables which must be set. They should be something like:

OPENCASCADE_INCLUDE_DIR - C:\Program Files\OpenCASCADE6.2.0\ros\inc

OPENCASCADE_LIBRARY_DIR - C:\Program Files\OpenCASCADE6.2.0\ros\win32\lib

It is safe to ignore 'OPENCASCADE_DEBUG_LIBRARY_DIR-NOTFOUND'.

If you wish, switch on 'BUILD_DOCUMENTATION' and 'BUILD_EXAMPLES' and 'Configure' again. To build the documentation, Doxygen is required. Once configuring is done, click OK to generate the Visual Studio project files.

Now, using Windows Explorer, navigate to the TexGen build directory (C:\Program Files\TexGen3.2.0) and launch Visual Studio by double-clicking on the file TexGen.sln. Set the configuration to 'Release', and in the Solution Explorer, select the 'INSTALL' project. Choose Build->Build Solution (or press F7). This will take a few minutes to compile the code. When the compiler has finished, the TexGen GUI executable file can be found under C:\Program Files\texgen3.2.0\release\TexGenGUI.exe.


Cygwin and gcc

A limited build (without graphics) can be made under cygwin, this is a UNIX emulation environment available at www.cygwin.com. This can exist peacefully next to the native windows version. Cygwin creates a unix-style file system within your windows installation. If you choose c:/cygwin as your install directory, your HOME will be at c:/cygwin/home/<username>/.

Download cygwin and install packages

Install gcc, g++, wget, make and cmake using the setup.exe program from the cygwin website. For the mesh generator and python interface to work we currently need VTK and swig.

This downloads and installs swig from source (when starting the cygwin shell you can paste this into the command line, otherwise write it to a file and run it with sh).

mkdir progs
cd progs 
SWIG=swig-1.3.31
wget -nc http://kent.dl.sourceforge.net/sourceforge/swig/$SWIG.tar.gz
tar xzvf $SWIG.tar.gz 
cd $SWIG
./configure 
make 
make install

This downloads and installs VTK from source, in the ccmake stage, use the cmake graphical commands to get a working install.

VTK=vtk-5.0.3
wget -nc http://www.vtk.org/files/release/5.0/$VTK.tar.gz
tar xzvf $VTK.tar.gz
mkdir vtkbin
cd vtkbin
ccmake ../VTK
make 
make install

Install TexGen from source

Now we can proceed to install texgen, as an example we'll work in ~/temp/texgen

cd ~; mkdir temp; cd temp; mkdir texgen; cd texgen
svn checkout https://texgen.svn.sourceforge.net/svnroot/texgen/TexGen/trunk/ TexGen
cd .. ; mkdir tbin; cd tbin
ccmake ../texgen
make 
make install

This should result in a working texgen install in ~/temp/texgen/tbin.

Unix compile

Notes

If you are installing to a system where you don't have root access (i.e. this computer does not belong to you) you won't be able to install the software using the default configure script. This is because by default software is installed to the /usr/local directory. If you are not a systems administrator then you will quite rightly not have write access to this folder. All is not lost! You can still install software into your home directory. In order to do this you should always call the configure script with the following parameter: --prefix=$HOME. This goes for all the software to be installed below. All executables will then be placed in ~/bin, libraries in ~/lib, includes in ~/include, etc...

In the guide below the parameter is included in italic. If you do in fact have root access then it is recommended to omit this parameter and install to the default directory so that other users will also have access to the software.

Get TexGen from Subversion repository

Install Subversion

Download Subversion and unpack. Open a shell in extracted folder and type:

./configure --with-ssl --prefix=$HOME
make
make install

Notes:

  • You will need to install Subversion with SSL support since TexGen is hosted on sourceforge which uses SSL. If you don't configure with the --with-ssl flag you will get an error when trying to checkout TexGen in the next step.
  • If you have trouble installing the latest version of Subversion, try installing version 1.3 as it does not require a seperate dependencies package.

Checkout

Open a shell in folder you wish to place TexGen (e.g. ~/):

svn checkout https://texgen.svn.sourceforge.net/svnroot/texgen/TexGen/trunk/ TexGen

Notes:

  • The first parameter tells SVN to get the files for the first time
  • The second parameter is the location of the TexGen svn repository
  • The final parameter is the subfolder to put the files in

Update

The checkout command only needs to performed once. SVN keeps track of where the code was originally obtained and can update to the latest version without having to re-specify the location. In order to do that open a shell in the folder where TexGen was originally checkout (e.g. ~/TexGen) and type:

svn update

or if you are in a hurry you can type the shorter version:

svn up

Compile source

Install CMake

Download CMake and unpack. Open a shell in extracted folder and type:

./configure --prefix=$HOME
make
make install

Compile TexGen core

Open a shell in the folder with the TexGen source code (e.g. ~/TexGen):

mkdir bin
cd bin
ccmake ../

Press 'c' to configure. When a warning pops up telling you it can't find such and such a file press 'e' to close it. You will now need to specify which components of TexGen to build and where their dependencies can be found. Use the up and down arrows to move the caret and press enter to modify options. Do this to set BUILD_GUI, BUILD_PYTHON_INTERFACE and BUILD_RENDERER to OFF. You are basically telling CMake not to attempt to build these components, which means that you won't need to have installed their dependencies.

Similarly to the --prefix=$HOME parameter to the configure script, you can tell CMake to install TexGen to your home directory by changing CMAKE_INSTALL_PREFIX to ~/. Note that it won't actually install anything until you get type make install.

Now press 'c' again to update the changes.

Hopefully now that all the additional modules have been switched off no errors will be shown. Press 'g' to generate the makefiles and exit. At the shell type:

make
make install

Note that at this point you have only built and installed the TexGen Core library which doesn't actually do anything on its own. If you plan to incorporate TexGen into your own C++ program then this is enough, however if you would like to interface with TexGen from a Python script or Graphical User Interface then follow the steps below.

Compiling optional modules

Python interface

Download Python and unpack. Open a shell in the extracted folder and type:

./configure --prefix=$HOME
make
make install

Download SWIG and unpack. Open a shell in the extracted folder and type:

./configure --prefix=$HOME
make
make install

Open a shell in the folder where you called ccmake from for the first time (e.g. ~/TexGen/bin):

ccmake ../

Use the up and down arrows to reach BUILD_PYTHON_INTERFACE and press Enter to set it to ON. Then press 'c' to configure. You will probably get a warning saying you need to specify the location of SWIG and/or Python, press 'e' to close it.

Set the PYTHON_INCLUDE_PATH, PYTHON_LIBRARY, PYTHON_SITEPACKAGES_DIR, SWIG_DIR and SWIG_EXECUTABLE parameters correctly where necessary. If you have installed packages to your home directory then they should look something like this:

PYTHON_INCLUDE_PATH: ~/include/python2.5
PYTHON_LIBRARY: ~/lib/python2.5/config/libpython2.5.a
PYTHON_SITEPACKAGES_DIR: ~/lib/python2.5/site-packages
SWIG_DIR: ~/bin
SWIG_EXECUTABLE: ~/bin/swig

Once that is done press 'c' again. You may need perform this process over several iterations. When everything is set correctly press 'g' to generate the makefiles.

At the shell type:

make
make install

Assuming the build completed without errors you should now be able to access TexGen functions from within Python. In order to check everything worked as planned open Python in interactive mode by typing:

python

Then from within Python type:

from TexGen.Core import *
CTexGen.GetInstance().GetVersion()

This should display the version of TexGen installed.

Troubleshooting

Q: I get the following error when linking _Core.so:

libpython2.5.a(abstract.o): relocation R_X86_64_32 against `a local symbol'
can not be used when making a shared object; recompile with -fPIC

A: Try removing libpython2.5.a from the libraries to link to by setting PYTHON_LIBRARY to a bogus path, e.g.:

PYTHON_LIBRARY: ~/

By doing so you may receive a warning similar to this:

Warning: Ignoring path found in link libraries for target: _Core, path is:
/home/username. Expected a library name or a full path to a library name.

This warning may be ignored.