如何获得RPATH与$ ORIGIN工作上Code :: Blocks GCC? [英] How to get RPATH with $ORIGIN to work on Code::Blocks GCC?

查看:598
本文介绍了如何获得RPATH与$ ORIGIN工作上Code :: Blocks GCC?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图将包含特殊字符串$ ORIGIN的RPATH链接到使用GCC与Code :: Blocks IDE构建的可执行文件中。我已指定

  -Wl,-R $ ORIGIN 

在项目的链接器选项中,但是命令行输出到GCC是错误的(为了清楚起见):

  g ++ -Wl,-R 

方法来为Code :: Blocks指定这个参数?

解决方案

谁决定让令牌$ ORIGIN是一个邪恶的混蛋程序员地狱的一个特殊的地方。因为'$'是bash和其他脚本语言的特殊字符,例如make,它拧紧一切,除非仔细逃脱。更糟糕的是,根据您使用的构建环境,如何正确转义的细节可能会改变。



在bash中,您需要在前面加一个反斜杠的$:

  -Wl,-R\ $ ORIGIN 
pre>

Code :: Blocks显然也将$视为特殊。然后,无论子进程控制器Code :: Blocks发送命令将反斜杠视为特殊。所以,反斜杠和$需要加倍以正确转义。因此,在Code :: Blocks链接器设置中,您需要指定:

  -Wl,-R\\ $$ ORIGIN 

...输出:

  -Wl,-R\\ $ ORIGIN 

...到构建日志,但shell实际上被发送:

  -Wl,-R\ $ ORIGIN 

...如上所述产生所需的结果。



多痛苦。


I'm trying to link an RPATH containing the special string $ORIGIN into an executable built using GCC with the Code::Blocks IDE. I've specified

-Wl,-R$ORIGIN

in the linker options for the project, but the command line output to GCC is wrong (stripped for clarity):

g++ -Wl,-R

What is the correct way to specify this argument for Code::Blocks?

解决方案

Whoever decided to make the token $ORIGIN is an evil bastard who deserves a special place in programmer hell. Since '$' is a special character for bash and other scripting languages like make, it screws everything up unless carefully escaped. Even worse, depending on which build environment you're using, the specifics of how to escape properly will likely change.

In bash, you need to stick a backslash in front of the $:

-Wl,-R\$ORIGIN

Code::Blocks apparently also treats the $ as special. Then, whatever subprocess controller Code::Blocks sends the command to treats the backslash as special. So, both the backslash and the $ need to be doubled up to get escaped properly. Therefore, in Code::Blocks linker settings, you need to specify:

-Wl,-R\\$$ORIGIN

...which outputs:

-Wl,-R\\$ORIGIN

...to the build log, but the shell actually gets sent:

-Wl,-R\$ORIGIN

...which as mentioned above produces the desired result.

What a pain.

这篇关于如何获得RPATH与$ ORIGIN工作上Code :: Blocks GCC?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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