Ok, Long time no see.. Was busy with too much work. Got a little bit of free time in the last couple of weeks and was mucking around with some Artifical Neural Network packages out there and ran into an issue with FANN 2.1.0 Beta.
I was able to compile and install the core libfann without any issues, however when I tried compiling the python binding pyfann I ran into some issues, first ubuntu did not have any of the python dev packages installed by default so installed them with
sudo apt-get install python-dev
and then installed the swig package
sudo apt-get install swig
and then when tried compiling it with make, I got this
Running SWIG before: swig -c++ -python pyfann/pyfann.i
copying pyfann/libfann.py -> build/lib.linux-x86_64-2.5/pyfann
building ‘pyfann._libfann’ extension
gcc -pthread -fno-strict-aliasing -DNDEBUG -g -fwrapv -O3 -Wall -Wstrict-prototypes -fPIC -DSWIG_COMPILE -I../src/include -I/usr/include/python2.5 -c pyfann/pyfann_wrap.cxx -o build/temp.linux-x86_64-2.5/pyfann/pyfann_wrap.o
cc1plus: warning: command line option “-Wstrict-prototypes” is valid for Ada/C/ObjC but not for C++
g++ -pthread -shared build/temp.linux-x86_64-2.5/pyfann/pyfann_wrap.o ../src/doublefann.o -L/usr/lib -lpython2.5 -o build/lib.linux-x86_64-2.5/pyfann/_libfann.so
/usr/lib64/gcc/x86_64-suse-linux/4.1.2/../../../../x86_64-suse-linux/bin/ld: ../src/doublefann.o: relocation R_X86_64_32 against `a local symbol’ can not be used when making a shared object; recompile with -fPIC
../src/doublefann.o: could not read symbols: Bad value
collect2: ld returned 1 exit status
error: command ‘g++’ failed with exit status 1
make: *** [build-stamp] Error 1
So after some more mucking around I was able to isolate the issue to the CPPFLAGS “-fPIC” in the Makefile. I knew I had to add this somewhere but when I added it to the local Makefile under python folder it did not help, added it to the root folder Makefile did not help. Finally I figured out the steps to get it right.
Run ./configure on root
Then add “-fPIC” to the CPPFLAGS tag in Makefile’s on the root folder and src folder
Then run make and sudo make install for the libfann;
Then cd to python and do “make” or “python setup install”.
This should work.
Hope this helps.