Installation of FANN library

From COSSAN Wiki
Jump to: navigation, search

Fast Artificial Neural Network (FANN) Library is a free open source Neural Network library, which implements multilayer artificial neural networks in C with support for both fully connected and sparsely connected networks [1].
To add the library to the OpenCossan path in Windows please follow the instructions below.

Compilation Requirements

Please note that to be able to use the FANN library in OpenCOSSAN, the software listed below must be installed on your computer.
If necessary, follow the related sections to get the software and complete the installation [2].


  • Download and install the gedit text editor for Windows. We used this package: gedit-setup-2.30.1-1.exe (32-bit).
    • To ensure that Windows knows that gedit is a text editor, use Windows Explorer to navigate to <your_drive>:\Program Files (x86)\gedit\share\doc and right-click on README, and select Open. In the dialog, click Browse, then select <your_drive>:\Program Files (x86)\gedit\bin\gedit.exe, and click OK to open the file. This will ensure that gedit appears in the list of editors for other text files you want to open in future.
    • Note: be aware that some other installers may modify your system PATH in a way that causes gedit to break. If you start to get errors when launching gedit, this is probably what has happened.


MinGW is a minimal GNU/GCC environment for Windows. MSYS is a command-line environment based on MinGW that mimics the Linux environment sufficiently well to allow a large portion of Linux-compatible software to also be compilable under Windows. There are many different combinations of ways to set up this environment. And things are made quite a bit more complicated by the fact that the official MinGW project does not support the 64-bit fork MinGW-w64, and as yet (Aug 2013) there is no nicely-integrated environment that supports installing everything automatically. Based on our experience in particular with difficulties in building recent versions of IPOPT, this is therefore our current preferred approach:

  • Download mingw-get-setup.exe from the official MinGW (32-bit) project page (we used version 0.6.2-beta-20131004-1), and run it:
    • Select to install MinGW to the directory c:\MinGW\32 (this is not the default location)
    • Select not to install the graphical user interface
  • Open gedit and edit the file c:\mingw\32\var\lib\mingw-get\data\profile.xml and replace the entire contents of the file with the following text:
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<profile project="MinGW" application="mingw-get">
  <repository uri=""/>
  <system-map id="default">
    <sysroot subsystem="mingw32" path="%R" />
    <sysroot subsystem="MSYS" path="%R/../msys" />
<your_drive>:\mingw\32\bin\mingw-get install msys-core msys-base msys-vim msys-wget msys-patch msys-flex msys-bison
  • Using gedit, create the file c:\mingw\msys\etc\fstab with the following content:
<your_drive>:/mingw/32   /mingw
  • Using Windows Explorer, create a shortcut to the file <your_drive>:\mingw\msys\msys.bat and place the shortcut on the desktop. You may wish to set the icon of the shortcut to the icon file <your_drive>:\mingw\msys\msys.ico.
  • Double-click your new desktop shortcut to msys.bat. You should see a console window as follows:

Our setup will be a bit of a hack of the standard MinGW environment. We use the official MinGW project to provide the MSYS environment, but then we use the MinGW-w64 project (as below) to provide the actual compiler, since we want 64-bit support. Our file structure will be

  • c:\
    • mingw\ (we install everything under this single top-level directory)
      • 64\ (the 64-bit compiler and all our 64-bit compiled-and-installed libraries will live here)
      • 32\ (the mingw-get binary will already be inside here, as well as the 32-bit compiler if we install it later)
      • msys\ (the MSYS environment, and loads of useful non-compiler tools can be installed here, but they shouldn't have any binary dependencies in c:\mingw\64 or <your_drive>:\mingw\32, or things will get broken!)

In principle, all we need to do to switch between the 64-bit and 32-bit build environments is to edit the text file /etc/fstab (changing '32' to '64' or vice versa), then reload MSYS. In other words, if you want to now switch to 64-bit mode, you would modify /etc/fstab to read

<your_drive>:/mingw/64   /mingw

After making this change, be sure to close and re-open your MinGW/MSYS command window (re-open it using the MSYS icon that you created on your desktop).

MinGW-w64 (Minimalist GNU for Windows, 64-bit) is a fork of the earlier MinGW GCC (GNU Compiler Collection: C, C++ and Fortran compilers and associated tools). MinGW-w-64 was carefully extended to include support for 64-bit Windows. Despite the name, MinGW-w64 both runs on and builds binaries for both 32-bit and 64-bit Windows, but you need to make sure you download the right package according to which platform you are running on, and which platform you want to target.

  • Download the TDM-GCC 'MinGW-w64 sjlj' installer for from this page. We used tdm64-gcc-4.7.1-3.exe.
  • Install the TDM-GCC package into the directory c:\mingw\64, selecting to install all components. Select not to add MinGW-w64 to the PATH.
  • After the installer completes, use the Start menu, right-click on 'Computer', select 'Properties' then 'Advanced Systems Settings' then 'Advanced' tab, click button 'Environment variables'. Under system variables, edit the variable named PATH and from then end of the path, remove c:\mingw\64\bin. We don't want this in the path because it messes with gedit, and will also cause confusion when running 32-bit compilers.
  • Open the MSYS shell (make sure you are in 64-bit mode, as mentioned above) by double-clicking your new desktop shortcut, and type gcc --version. You should see
john@win7_64 ~
$ gcc --version
gcc.exe (tdm64-1) 4.7.1
Copyright (C) 2012 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
  • In gedit, open (or create) the file c:\mingw\msys\home\yourusername\.profile (no file extension). In that file, paste in the following text, and save the resulting file.
# we use the reported architecture of the 'gcc' in our path to
# determine which Python and other utilities we will be using.
_arch=`gcc -dumpmachine`
#echo "ARCH=$_arch"
if grep "^x86_64-" <<< "$_arch" >/dev/null ; then
export PATH=$PATH:$_pydir:$_pydir/Scripts
# note that mingw-get will still install all its stuff to c:\mingw\32,
# because of the contents of its profile.xml file.
alias mingw-get="/c/mingw/32/bin/mingw-get"

Note: the above TDM 64-bit installer does not install a fortran compiler, but a fortran compiler is required for building ASCEND. The alternative appears to be to use the latest tdm-gcc-webdl.exe downloader-installer. Select all options, but select not to install to PATH.


Download the latest release of the CMAKE windows installer from (currently cmake-3.7.2-win64-x64.msi). Run the installer and, once completed the setup, ensure the bin directory is in the windows path.

Compilation Instructions

Run msys.bat through the shortcut previously created on the desktop. In the command prompt give the commands:

cd <your_opencossan_drive>
cd <your_opencossan_directory>/OpenSourceSoftware/src/FANN-2.2.0-Source
cmake . -DCMAKE_INSTALL_PREFIX=/E/OpenCossan/OpenSourceSoftware/dist/Windows/<windows_version_number>/<windows_architecture> -DCMAKE_BUILD_TYPE="Release" -G "MSYS Makefiles"
make install

Note:please note the normal slash (/) in place of the usual windows backward slash (\) directory separator Note: <windows_version_number> is returned from command line with the `ver` command. <windows_architecture> is win32 for a 32-bit system (deprecated) and win64 for a 64-bit system.

Rename the files .dll.a in the destination folder to .lib for compatibility with Matlab mex in Windows. Also, the file libfann.lib should be copied to mex\src folder.

Use the FANN library

Add the location <your_opencossan_directory>\OpenSourceSoftware\dist\Windows\<windows_version_number>\<windows_architecture> in the environment variable PATH of your computer. See e.g. [3] for instructions on how to modify PATH.

<windows_version_number> and <windows_architecture> are the one used in the compilation command.

To load and use the FANN library on the Risk Cluster's MATLAB, the following commands have to be typed in before starting MATLAB so as to specify the Library path for COSSAN:


See also