如何在makefile中指定RPATH?

编程入门 行业动态 更新时间:2024-10-25 03:26:18
本文介绍了如何在makefile中指定RPATH?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我正在尝试在二进制文件中指定rpath. 我的makefile看起来像这样-

I'm trying to specify rpath in my binary. My makefile looks like this-

CC=gcc CFLAGS=-Wall LDFLAGS= -rpath='../libs/' main: main.c gcc -o main main.c clean: rm -f main main.o

但是当我使用命令readelf -a ./main | grep rpath查询rpath时,我什么也没得到 我尝试将rpath指定为LDFLAGS= "-rpath=../libs/",但即使这样似乎也不起作用.

But when I query rpath using command readelf -a ./main | grep rpath I get nothing I've tried specifying rpath as LDFLAGS= "-rpath=../libs/" but even that doesn't seem to work.

有人可以发布一个示例,说明如何在Makefile中指定rpath吗?

Can someone please post an example on how should I specify rpath in a makefile?

GCC和ld版本是-

GCC and ld versions are-

gcc (Ubuntu/Linaro 4.5.2-8ubuntu4) 4.5.2 GNU ld (GNU Binutils for Ubuntu) 2.21.0.20110327

推荐答案

如果设置变量,则可能应该使用它们.不这样做是很愚蠢的,尤其是当make不会为您神奇地设置这些变量时! :)

If you set the variables, you should probably use them. It's silly not to, especially when make won't magically set those variables for you! :)

main: main.c $(CC) $(CFLAGS) $(LDFLAGS) -o main main.c

另一个问题是LDFLAGS,应该是

Another problem is LDFLAGS, it should be

LDFLAGS="-Wl,-rpath,../libs/"

用于将选项传递给链接器的常用 gcc 开关是-Wl,,这是必需的,因为 gcc 本身可能不了解裸露的-rpath链接器选项.尽管某些版本的 gcc 的某些版本接受-rpath,但我从未见过在 gcc 手册页或信息页中记录过该文档.为了获得更好的可移植性,应首选-Wl,-rpath.

The usual gcc switch for passing options to linker is -Wl,, and it is needed because gcc itself may not understand the bare -rpath linker option. While some builds of various versions of gcc accept -rpath, I have never seen it documented in gcc man pages or info pages. For better portability, -Wl,-rpath should be preferred.

更多推荐

如何在makefile中指定RPATH?

本文发布于:2023-11-27 21:00:12,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1639582.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:如何在   makefile   RPATH

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!