Jay Taylor | programmer notes

Oct/10

6

HOWTO fix -fPIC errors

Whilst compiling fann/pyfann on a 64-bit Ubuntu machine, I got that annoying -fPIC compilation error:

../src/include/fann_internal.h:73: warning: function declaration isnât a prototype
gcc -pthread -shared -Wl,-O1 -Wl,-Bsymbolic-functions build/temp.linux-x86_64-2.6/pyfann/pyfann_wrap.o build/temp.linux-x86_64-2.6/pyfann/fann_helper.o ../src/doublefann.o -o build/lib.linux-x86_64-2.6/pyfann/_libfann.so
/usr/bin/ld: ../src/doublefann.o: relocation R_X86_64_32 against `.rodata.str1.1′ 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 ‘gcc’ failed with exit status 1

I did some googling and promptly found this Gentoo guide for resolving -fPIC errors,

http://www.gentoo.org/proj/en/base/amd64/howtos/index.xml?part=1&chap=3

The case that ended up being relevant was:

3.f. Case 3: Lack of `-fPIC’ flag in the software to be built

This is the most common case. It is a real bug in the build system and should be fixed in the ebuild, preferably with a patch that is sent upstream. Assuming the error message looks like this:

Code Listing 6.1: A sample error message
.libs/assert.o: relocation R_X86_64_32 against `a local symbol' can not be used
when making a shared object; recompile with -fPIC .libs/assert.o: could not
read symbols: Bad value

This means that the file assert.o was not compiled with the -fPIC flag, which it should. When you fix this kind of error, make sure only objects that are used in shared libraries are compiled with -fPIC.

In this case, globally adding -fPIC to C[XX]FLAGS resolves the issue, although this practice is discouraged because the executables end up being PIC-enabled, too.

I was able to resolve the errors by exporting the -fPIC flags to the CC and CXX environmental variables, running ./configure again, and recompiling.

export CC=”gcc -fPIC”
export CXX=”g++ -fPIC”
make distclean; make clean
./configure
make
sudo make install
cd python
python setup.py build
sudo python setup.py install

It’s a nice win :)  Hopefully next time I encounter this problem I’ll remember.

At any rate, now with pyfann working, I can now resume this tutorial on extracting paragraphs from html.

Keywords:

“relocation R_X86_64_32 against” “can not be used when making a shared object;” “recompile with -fPIC”

compiling, compilation, linux, errors, 64-bit, fPIC, fann, pyfann, ai, recompiling, recompilation, programming, code, coding, gcc, g++

RSS Feed

No comments yet.

Leave a comment!

You must be logged in to post a comment.

<<

>>

Find it!