gcc - 我不明白 -Wl,-rpath -Wl,

标签 gcc ld rpath

为方便起见,我在下面添加了相关联机帮助页。

首先我的(错误)理解:如果我需要用 , 分隔选项,那意味着第二个 -Wl 不是另一个选项,因为它在 之前>, 这意味着它是 -rpath 选项的参数。

我不明白 -rpath 怎么会有 -Wl,. 参数!

在我看来有意义的是:

-Wl,-rpath .

这应该使用当前目录参数调用 -rpath 链接器选项。


man gcc:

-Wl,option

Pass option as an option to the linker. If option contains commas, it is split into multiple options at the commas. You can use this syntax to pass an argument to the option. For example, -Wl,-Map,output.map passes -Map output.map to the linker. When using the GNU linker, you can also get the same effect with `-Wl,-Map=output.map'.

男人 ld:

-rpath=dir

Add a directory to the runtime library search path. This is used when linking an ELF executable with shared objects. All -rpath arguments are concatenated and passed to the runtime linker, which uses them to locate shared objects at runtime. The -rpath option is also used when locating shared objects which are needed by shared objects explicitly included in the link;

最佳答案

gcc-Wl,xxx 选项将逗号分隔的标记列表作为空格分隔的参数列表传递给链接器。所以

gcc -Wl,aaa,bbb,ccc

最终成为链接器调用

ld aaa bbb ccc

在你的例子中,你想说“ld -rpath .”,所以你将它作为 -Wl,-rpath,. 传递给 gcc 或者,你可以指定 -Wl 的重复实例:

gcc -Wl,aaa -Wl,bbb -Wl,ccc

注意 aaa 和第二个 -Wl 之间没有逗号。

或者,在您的情况下,-Wl,-rpath -Wl,.

关于gcc - 我不明白 -Wl,-rpath -Wl,,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41455979/

相关文章:

qt - 使用 Qt Creator 在 Unix 系统中开发 Qt 应用程序

c++ - 从源代码编译与 deb 包编译

c - OpenMp 运算符 != 的无效控制谓词

gcc - 拦截 GNU tar 的 openat() 系统调用

c++ - 在执行期间检测下溢

linux - 尝试包含 -lcrypto 时 RISCV gcc 的编译错误

c++ - 在 C++ 中将库链接到 linux 二进制文件

c++ - 为什么 ld 链接器允许使用相同方法定义多个类?

linux - 在调用/lib/ld-linux.so.2 中的 _start 函数之前发生了什么?

python - 在 Ubuntu 中编译 Python 2.6.6 并需要外部包 wxPython、setuptools 等...