如何使用 -fPIC 标志重新编译 libperl.a 目标文件? [英] How to recompile libperl.a object files with -fPIC flag?

查看:55
本文介绍了如何使用 -fPIC 标志重新编译 libperl.a 目标文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这个问题是在尝试修复一些安装问题时出现的使用 QtCore4.在某些时候 make 尝试运行以下命令:

/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:

由于链接器的以下错误消息而失败:

/usr/bin/ld:/home/hakon/perlbrew/perls/perl-5.24.1/lib/5.24.1/x86_64-linux/CORE/libperl.a(toke.o):重新定位 R_X86_64_PC32 对符号`PL_curcop' 制作时不能使用共享对象;用 -fPIC 重新编译/usr/bin/ld: 最终链接失败:值错误collect2: 错误: ld 返回 1 个退出状态

从错误消息来看,在我看来,目标文件(这里:toke.o)在libperl.a 是在没有设置 -fPIC 标志的情况下编译的.

我现在的问题是:

  • 如何使用 -fPIC 重新编译 libperl.a 中的目标文件?
  • 这次重新编译会不会导致其他与本次无关的问题?QtCore4(因为很可能会使用libperl.a(链接与) 由与 QtCore4 无关的其他应用程序/程序)?

我使用的是 Ubuntu 16.10 和 perl 版本 5.24.1.

解决方案

如何使用 -fPIC 重新编译 libperl.a 中的目标文件

通过使用 -fPIC 标志重新编译 libperl.a.

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

<块引用>

这种重新编译是否会导致其他与 QtCore4 无关的问题(因为 libperl.a 很可能会被其他与 QtCore4 无关的应用程序/程序使用(链接))?

是的.更喜欢共享的 libperl.-Duseshrplib

将 perl 嵌入共享库时需要这样做.您可以取消 ELF 所需的 -fPIC 技巧,但共享 libperl 使其变得更容易.

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.

解决方案

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.

这篇关于如何使用 -fPIC 标志重新编译 libperl.a 目标文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆