如何在makefile中指定RPATH? [英] How to specify RPATH in a makefile?

查看:1745
本文介绍了如何在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?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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