静的ライブラリを共有ライブラリにリンクしようとしていますが、次のエラーが発生しています
/usr/bin/ld: ../../../libraries/log4cplus/liblog4cplus.a(fileappender.o): 再配置 R_X86_64_32S は、共有オブジェクトを作成するときに「ローカル シンボル」に対して使用できません。-fPIC で再コンパイル ../../../libraries/log4cplus/liblog4cplus.a: シンボルを読み取れませんでした: 値が正しくありません collect2: ld が 1 つの終了ステータスを返しました
しかし、これは32ビットマシンでそのようなエラーなしで機能しました。-fPIC
問題を解決しなかった Makefile に手動でフラグを追加しようとしました
ここで-whole-archive
提案されているようにフラグを試しましたが、成功しませんでした。
/usr/bin/ld: ../../../libraries/log4cplus/liblog4cplus.a(appenderattachableimpl.o): vtable for log4cplus::spi::AppenderAttachable に対する再配置 R_X86_64_32S は、共有オブジェクト; -fPIC で再コンパイル ../../../libraries/log4cplus/liblog4cplus.a(appenderattachableimpl.o): シンボルを読み取れませんでした: 値が正しくありません collect2: ld が 1 つの終了ステータスを返しました
liblog4cplus.a の作成:
unzip log4cplus-1.1.0.zip
./configure --enable-static=yes --enable-threads=yes
vi Makefile
-fPIC を CXXFLAGS と CFLAGS に追加make
次に、共有ライブラリをコンパイルします。
g++ -frtti -w -c -fPIC -I"Include_Directory" myfile.cpp
g++ -shared -fPIC -frtti -I"Include_Directory" -o mysofile.so myfile.o -Wl,--whole-archive "../../../libraries/log4cplus/liblog4cplus.a" -Wl,--no-whole-archive -ldl