如何使用 $ORIGIN 获取 RPATH 以在 Code::Blocks GCC 上工作? [英] How to get RPATH with $ORIGIN to work on Code::Blocks GCC?

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

问题描述

我正在尝试将包含特殊字符串 $ORIGIN 的 RPATH 链接到使用 GCC 和 Code::Blocks IDE 构建的可执行文件中.我已经指定了

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

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

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

g++ -Wl,-R

为 Code::Blocks 指定此参数的正确方法是什么?

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

推荐答案

决定制作令牌 $ORIGIN 的人是一个邪恶的混蛋,应该在程序员的地狱中占有一席之地.由于 '$' 是 bash 和其他脚本语言(如 make)的特殊字符,因此除非小心转义,否则它会搞砸一切.更糟糕的是,根据您使用的构建环境,如何正确转义的细节可能会发生变化.

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.

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

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

-Wl,-R$ORIGIN

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

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

...输出:

-Wl,-R\$ORIGIN

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

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

-Wl,-R$ORIGIN

...如上所述产生了预期的结果.

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

好痛.

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

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