Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to recompile libperl.a object files with -fPIC flag?

Tags:

This question arose when trying to fix some installation problems with QtCore4. At some point make tried to run the following command:

/usr/bin/c++  -fPIC -fwrapv -fno-strict-aliasing -pipe -fstack-protector-strong \
 -I/usr/local/include -D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64 -O3 -DNDEBUG  \
 -shared -Wl,-soname,QtCore4.so -o ../../blib/arch/auto/QtCore4/QtCore4.so \
 CMakeFiles/perlqtcore4.dir/binding.cpp.o \
 CMakeFiles/perlqtcore4.dir/handlers.cpp.o \
 CMakeFiles/perlqtcore4.dir/marshall_types.cpp.o \
 CMakeFiles/perlqtcore4.dir/util.cpp.o \
 CMakeFiles/perlqtcore4.dir/QtCore4.c.o \
 -lQtCore -lQtGui -lQtNetwork \
 /home/hakon/perlbrew/perls/perl-5.24.1/lib/5.24.1/x86_64-linux/CORE/libperl.a \
 ../../smokeqt/qtgui/libsmokeqtgui.so.3.0.0 \
 ../../smokeqt/qtnetwork/libsmokeqtnetwork.so.3.0.0 \
 -lpthread -lnsl -ldl -lm -lcrypt -lutil -lc -lQtGui -lQtNetwork \
 ../../smokeqt/qtcore/libsmokeqtcore.so.3.0.0 -lQtCore \
 ../../smokegen/bin/libsmokebase.so.3.0.0 \
 -Wl,-rpath,/home/hakon/Qt4-0.99.0/smokeqt/qtgui:/home/hakon/Qt4-0.99.0/smokeqt/qtnetwork:/home/hakon/Qt4-0.99.0/smokeqt/qtcore:/home/hakon/Qt4-0.99.0/smokegen/bin: 

which failed with the following error message from the linker:

/usr/bin/ld: /home/hakon/perlbrew/perls/perl-5.24.1/lib/5.24.1/x86_64-linux/CORE/libperl.a(toke.o): 
  relocation R_X86_64_PC32 against symbol `PL_curcop' can not be used when making
  a shared object; recompile with -fPIC
/usr/bin/ld: final link failed: Bad value
collect2: error: ld returned 1 exit status

From the error message, it seems to me that the object files (here: toke.o) in libperl.a was compiled without the -fPIC flag set.

The questions I have now are:

  • How can I recompile the object files in libperl.a with -fPIC ?
  • Could this recompilation cause other problems not related to QtCore4 (since it is likely that libperl.a will be used (linked with) by other applications/programs not related to QtCore4)?

I am using Ubuntu 16.10 and perl version 5.24.1.

like image 932
Håkon Hægland Avatar asked Apr 04 '17 09:04

Håkon Hægland


1 Answers

How can I recompile the object files in libperl.a with -fPIC

By recompiling libperl.a with the -fPIC flag.

./Configure -des -Accflags=-fPIC ...

Could this recompilation cause other problems not related to QtCore4 (since it is likely that libperl.a will be used (linked with) by other applications/programs not related to QtCore4)?

Yes. Prefer a shared libperl. -Duseshrplib

Which is required when embedding perl into shared libs. You can do away with the -fPIC trick which is required on ELF, but a shared libperl makes it much easier.

like image 183
rurban Avatar answered Oct 06 '22 11:10

rurban