“使用-fPIC重新编译";即使添加了-fPIC编译标志,错误仍然存​​在 [英] "Recompile with -fPIC" error persists even after adding -fPIC compile flag

查看:246
本文介绍了“使用-fPIC重新编译";即使添加了-fPIC编译标志,错误仍然存​​在的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经下载了一些我想从源代码编译的C ++.在构建目录中的命令行中依次运行cmake ../srcmake之后,出现以下错误:

I have downloaded some C++ which I want to compile from source. After running cmake ../src and then make from the command line, whilst in the build directory, I get the following error:

/usr/bin/ld: /usr/local/lib/libBulletCollision.a(btDbvtBroadphase.o):
relocation R_X86_64_32S against `_ZTV16btDbvtBroadphase' can not be used when making a shared object;
recompile with -fPIC

我相信这与尝试创建共享库有关,但没有提供必要的内存来做到这一点(尽管我对此并不完全了解...).无论如何,按照我所看到的建议,我尝试了以下方法:

I believe that this is something to do with trying to create a shared library, but not providing the necessary memory to do so (although I don't fully understand this...). Anyway, following the advice I've seen around, I tried the following instead:

make CXXFLAGS='-fPIC'

但是,这给了我与以前完全相同的错误.关于为什么这不能解决问题的任何想法?

However, this gives me exactly the same error as before. Any ideas as to why this did not solve the problem?

推荐答案

我相信Mark说错误与libBulletCollision.a有关时是正确的.您正在构建使用-fPIC构建的.so,但链接到未使用-fPIC.a.您将需要更改和构建静态库,或者使用-fPIC重建并安装新的从属libBulletCollision.a.

I believe Mark is correct when he says the error is about libBulletCollision.a. You are building a .so built with -fPIC but linking against a .a that did not use -fPIC. You will either need to change and build a static library or rebuild and install a new dependent libBulletCollision.a using -fPIC.

顺便说一句,您应该在cmake配置步骤中以一种更永久的方式将-fPIC标志添加到您的构建中,而不是以这种短暂的方式在运行make时覆盖CXXFLAGS.

By the way, you should add the -fPIC flag to your build in a more permanent way in the cmake configure step rather in this transient way overriding CXXFLAGS when running make.

在调试版本时,将make VERBOSE=1与cmake生成的makefile版本一起使用也很有帮助.

Also using make VERBOSE=1 with cmake generated makefile builds is quite helpful when debugging builds.

这篇关于“使用-fPIC重新编译";即使添加了-fPIC编译标志,错误仍然存​​在的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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