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.
Use the command `make' to recompile the source files that really need recompilation. Make the changes in the header files. Use the command `make -t' to mark all the object files as up to date. The next time you run make, the changes in the header files do not cause any recompilation.
The $@ and $< are called automatic variables. The variable $@ represents the name of the target and $< represents the first prerequisite required to create the output file.
The Cleanup Rule clean: rm *.o prog3 This is an optional rule. It allows you to type 'make clean' at the command line to get rid of your object and executable files. Sometimes the compiler will link or compile files incorrectly and the only way to get a fresh start is to remove all the object and executable files.
In makefiles for substantial projects, the rules and lists of files are often more complicated, using multiple symbols to convey commands, options, and lists of files. In this context, “relink” merely means that make will execute the command to link objects into an executable again.
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.
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:
CXX=g++ CXXFLAGS= -O3 -Wall ... ... %.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) $(CXX) -shared -Wl,-soname,$@ -o $@ $(OBJECTS)
And it worked!
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With