使用 -fPIC 选项重新编译,但该选项已在 makefile 中
当我执行 make 时,出现此错误:
relocation R_X86_64_32 against `vtable for Torch::MemoryDataSet' can not be used
when making a shared object; recompile with -fPIC
它表示我应该使用 -fPIC
选项重新编译。 我这样做了,添加 CFLAGS
和 CXXFLAGS
的 -fPIC
选项,但我仍然遇到相同的错误。 有什么办法可以解决这个问题吗? 我看到这个问题与使用64位机器有关,确实我正在使用一台。
I get this error when I do the make:
relocation R_X86_64_32 against `vtable for Torch::MemoryDataSet' can not be used
when making a shared object; recompile with -fPIC
It says that I should recompile with the -fPIC
option. I did that, adding
the -fPIC
option to CFLAGS
and CXXFLAGS
, but I still get the same error. Is there any way to solve this? I have seen that this problem is related with the use of a 64-bit machine, and it is true that I am using one.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(7)
我很久以前就遇到过这个问题,如果我没记错的话,修复方法是将 -fPIC 的位置移到命令行中 gcc 之后。 完全没有意义,现在更没有意义,但据我记得,这解决了它。
I had this problem quite a while back and if I remember correctly, the fix was moving the placement of -fPIC just after gcc in the command line. Made absolutely no sense, and less so now, but as I remember, that fixed it.
我遇到了同样的问题,但它有一个额外的转折。 @clintm 的答案解决了这个问题,但我想我应该在这里描述我的问题变体以供将来参考...
32 位机器上的 Makefile:
编译正确。 但是当我在 64 位机器上尝试时,相同的 Makefile 失败了。 我将“-fpic”更改为“-fPIC”,但仍然失败。 我将对象规则更改为:
仍然失败。
最后,我将“-fPIC”放入实际的编译器变量中(以便现在“-fPIC”出现在每个对象的规则和共享库的规则中):
它起作用了!
I encountered the same problem, but it had an extra twist. The answer by @clintm solved it, but I thought I would describe my variation of the problem here for future reference...
Makefile on 32-bit machine:
This compiled correctly. But the same Makefile failed when I tried it on a 64-bit machine. I changed "-fpic" to "-fPIC" and it still failed. I changed the object rule to:
and it still failed.
Finally, I placed "-fPIC" in the actual compiler variable (so that now "-fPIC" appears in the rule for each object and the rule for the shared library):
And it worked!
假设您有一些 makefile,例如:
只需添加 -fPIC 标志,如下所示:
对于 makefile 的其余部分依此类推。
Let's say you have some makefile like:
just add the -fPIC flag like so:
so on so forth with the rest of the makefile.
我在与 android-ndk 工具链交叉编译时遇到了这个问题。 我最终不得不使用
-fPIC
和-fPIE
在这种情况下都不适合我。I ran into this problem cross-compiling with the android-ndk toolchain. I ended up having to use
Neither
-fPIC
nor-fPIE
worked for me in this situation.我在 CentOS 7 机器上交叉编译shadowsocks-libev,同样的问题发生在我身上,它在我的笔记本电脑上完美运行,
但在 travis ci 上,它不起作用,我必须将 -fPIC 添加到 CC 和 CXX 才能让它发挥作用
I was cross compiling shadowsocks-libev on a CentOS 7 machine, the same problem happened to me, it works perfectly on my laptop with
but on travis ci, it did not work, I have to add -fPIC to CC and CXX in order to get it to work
升级gcc后我遇到了这个问题。 我有一个 .o 文件(sqlite)尚未被 Makefile 清理,因此我遇到了这个问题(假设因为它是用旧版本的 gcc 编译的)。 删除该文件并重建后,此错误消失了。
I had this issue after I upgraded gcc. I had one .o file (sqlite) that hadn't been cleaned by the Makefile and as a result I had this issue (assuming because it was compiled with an older version of gcc). After removing that file and rebuilding this error went away.
如果您要编译的项目有一个正确的配置脚本,请使用如下所示:
因此该标志将是所有 Makefile 的规则...
几天前我需要一个较旧的版本。 VLC 在 x64 机器上编译,它有一个很好的配置脚本;-)
if the project you'd like to compile has a correct configure script use like this:
so the flag will be all the Makefile's rule ...
few days before i've need an elder ver. of VLC to compile on an x64 machine, it has a nice configure script ;-)