log4cxx recompile with -fPIC

205 views Asked by At

I'm compiling a shared lib (.so) that use log4cxx library. I'm getting the following error:

liblog4cxx.a(level.o): relocation R_X86_64_32 against `.bss' can not be used when making a shared object; recompile with -fPIC

Have you any idea? should I recompile log4cxx with some special option?

1

There are 1 answers

1
Jakob Stark On

You are trying to link your shared library to a static library (liblog4cxx.a), which does not work, because all ingredients to a shared library must be compiled with the -fPIC (position independent code) option. Static libraries (typically seen with the *.a file suffix) are typically not compiled with this option.

Your problem could be caused by two different issues. Either the liblog4cxx library is also present as a shared library and your linker somehow does not find it and tries to use the static library instead, or the shared version of liblog4cxx is missing in your installation.

I therefore advice to look for the path where the liblog4cxx.a file is located (e.g. in /usr/lib or another directory if you installed the library in a custom directory) and then look for a liblog4cxx.so in the same directory. If you found a shared version you could try to explicitly specify the path to your linker with -l/full/path/to/your/liblog4cxx.so.

If there is no shared version of the library I'm afraid, that you must reconfigure it to produce a shared library and than recompile it.

For a more specific help, you should give some more background information, as the build process of c++ libraries and projects is highly system dependend. So try to give information as

  • Which operating system are you developing on? (Windows, a special Linux distribution, or iOS)
  • Did you compile liblog4cxx yourself or do you use a precompiled version
  • If you compiled it yourself, which options did you pass to the configuration system?
  • What is your build process? Are you using some build system like cmake or do you manually specify your compiler options?