I try to create a shared library called "logtest.so" by linking "liblog4cplus.a" that I have compiled with -fPIC
option on.
Here is "logtest.cpp" (which is simply used for testing purpose by copying from log4cplus website):
#include "log4cplus/logger.h"
#include "log4cplus/loggingmacros.h"
#include "log4cplus/configurator.h"
using namespace log4cplus;
void test()
{
initialize();
BasicConfigurator config;
config.configure();
}
Here is the command:
g++ -shared logtest.cpp -L . -llog4cplus -pthread -o liblogtest.so -lrt -fPIC
And here is the error message:
/usr/bin/ld: ./liblog4cplus.a(configurator.o): relocation R_X86_64_32S against `_ZTVN9log4cplus23ConfigureAndWatchThreadE' can not be used when making a shared object; recompile with -fPIC
./liblog4cplus.a: could not read symbols: Bad value
collect2: error: ld returned 1 exit status
By calling:
nm liblog4cplus.a | grep _ZTVN9log4cplus23ConfigureAndWatchThreadE
I get:
0000000000000000 V _ZTVN9log4cplus23ConfigureAndWatchThreadE
I tried to add "-Wl,-rpath,$ORIGIN"
, but still get the same error message.
I guess there is something to do with linking static library in a shared libary, but I tried all the suggestions and it still does not work.