通过 makefile 传递 gcc 标志
我正在尝试使用 llvm 构建一个 pass,并且我已经完成了 llvm 及其相关组件的构建。 但是,当我按照所有步骤构建通行证(包括 makefile 后运行 make 时,我得到以下内容
创建共享库时,不能使用针对“本地符号”的重定位 R_X86_64_32; 使用-fPIC重新编译
在尝试通过谷歌搜索错误消息来找到修复程序后,我发现这并不是 llvm 特有的。 一些解决方案建议我在运行配置时应该使用“--enable-shared”,但这对我的情况没有帮助。 现在我想使用 fPIC
重新构建 llvm,如错误所示。 但是我该如何使用 makefile 来做到这一点呢?
I am trying to build a pass using llvm and I have finished building llvm and its associated components. However, when I run make after following all the steps to build a pass including the makefile, I get the following
relocation R_X86_64_32 against `a local symbol' can not be used when making a shared object; recompile with -fPIC
After tyring to find a fix by googling the error message, I came to know that this is not specific to llvm. A few solutions suggested that I should use "--enable-shared" while running configure but that didn't help my case. Now I want to re-build llvm using fPIC
, as the error says. But how do I do this using the makefile?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
看起来您可以通过设置 shell 变量来添加 -fPIC (对于与位置无关的代码,您想要的共享库可以在任何地址加载):
查看 Makefile.rules,这些将被拾取并使用。 奇怪的是,它一开始就不存在。
编辑:
实际上,在 makefile 中阅读更多内容,我找到了 LLVM Makefile Guide 的链接。 从 Makefile.rules 中,在 Makefile 中设置 SHARED_LIBRARY=1 或 LOADABLE_MODULE=1(这意味着 SHARED_LIBRARY)会将 -fPIC 放入编译器标志中。
Looks like you could add the -fPIC (for position-independent code, something you want for a shared library that could be loaded at any address) by setting shell variables:
Looking at Makefile.rules, these will be picked up and used. Seems strange that it wasn't there to begin with.
EDIT:
Actually, reading more in the makefiles, I found this link to the LLVM Makefile Guide. From Makefile.rules, setting either SHARED_LIBRARY=1 or LOADABLE_MODULE=1 (which implies SHARED_LIBRARY) in Makefile will put -fPIC in the compiler flags.
如果您适度确信应该在任何地方使用“
-fPIC
”(或“-m32
”或“-m64
”,我需要更频繁),那么您可以使用“技巧”:这假定使用 Bourne/Korn/POSIX/Bash shell,并在运行配置脚本之前将环境变量 CC 设置为“
gcc -fPIC
”。 这(通常)确保所有编译都是使用指定的标志完成的。 为了设置编译的正确“位数”,这有时比您发现的各种其他机制更好 - 编译很难绕过它,除非完全忽略您指定要使用的 C 编译器的事实。If you are moderately convinced that you should use '
-fPIC
' everywhere (or '-m32
' or '-m64
', which I need more frequently), then you can use the 'trick':This assumes a Bourne/Korn/POSIX/Bash shell and sets the environment variable CC to '
gcc -fPIC
' before running the configure script. This (usually) ensures that all compilations are done with the specified flags. For setting the correct 'bittiness' of the compilation, this sometimes works better than the various other mechanisms you find - it is hard for a compilation to wriggle around it except by completely ignoring the fact you specified the C compiler to use.另一种选择是直接传递 -fPIC 以通过以下方式进行制作:
Another option is to pass -fPIC directly to make in the following way: