Take the 2-minute tour ×

I get this error when I do the make:

relocation R_X86_64_32 against `vtable for Torch::MemoryDataSet' can not be used 
when making a shared object; recompile with -fPIC

It says that I should recompile with the -fPIC option. I did that, adding the -fPIC option to CFLAGS and CXXFLAGS, but I still get the same error. Is there any way to solve this? I have seen that this problem is related with the use of a 64-bit machine, and it is true that I am using one.

share|improve this question
Is this an error from the linker or the compiler ? Did you clean all the object files before recompiling ? –  philant Dec 2 '08 at 6:38
Yes it is an error from the compiler and yes I clean all the objects and I still get the same error. Thank you. –  Eduardo Dec 2 '08 at 16:36
Related question stackoverflow.com/questions/1250608/… Should have checked yours before posting mine. –  Arjun Singri Aug 9 '09 at 6:19
add comment

3 Answers

I had this problem quite a while back and if I remember correctly, the fix was moving the placement of -fPIC just after gcc in the command line. Made absolutely no sense, and less so now, but as I remember, that fixed it.

share|improve this answer
this did work for me aswell... adding -fPIC directly after gcc in Makefile i.e CC=gcc -pthread -fPIC –  ashishsony Mar 10 '09 at 12:41
I encountered the same problem. moving "-fPIC" to directly after the "gcc" (as you wrote) worked for me as well. Puzzling. –  M.P. Jan 21 '13 at 15:12
add comment

I encountered the same problem, but it had an extra twist. The answer by @clintm solved it, but I thought I would describe my variation of the problem here for future reference...

Makefile on 32-bit machine:

%.o:  %.c
    $(CXX)  $(CXXFLAGS)  -fpic  -c  $<      

libmylibrary.so: $(OBJECTS)
    $(CXX) -shared -Wl,-soname,$@ -o $@   $(OBJECTS)

This compiled correctly. But the same Makefile failed when I tried it on a 64-bit machine. I changed "-fpic" to "-fPIC" and it still failed. I changed the object rule to:

%.o:  %.c
    $(CXX)  -fPIC  $(CXXFLAGS)  -c  $< 

and it still failed.

Finally, I placed "-fPIC" in the actual compiler variable (so that now "-fPIC" appears in the rule for each object and the rule for the shared library):

CXX=g++  -fPIC
CXXFLAGS= -g -O3 -Wall
%.o:  %.c
        $(CXX)    $(CXXFLAGS)   -c      -o $@    $<   

libalglib.so: $(OBJECTS)

And it worked!

share|improve this answer
add comment

if the project you'd like to compile has a correct configure script use like this:

$ ./configure 'CFLAGS=-g -O2 -fPIC ....' --enable-some-thing

so the flag will be all the Makefile's rule ...

few days before i've need an elder ver. of VLC to compile on an x64 machine, it has a nice configure script ;-)

share|improve this answer
add comment

Your Answer


