For convenience I added the relevant manpages below.
为了方便起见,我添加了下面的相关页面。
My (mis)understanding first: If I need to separate options with ,
, that means that the second -Wl
is not another option because it comes before ,
which means it is an argument to the -rpath
option.
我首先要理解的是:如果我需要将选项与之分开,这意味着第二个-Wl不是另一个选项,因为它之前出现过,这意味着它是-rpath选项的一个参数。
I don't understand how -rpath
can have a -Wl,.
argument!
我不明白-rpath怎么能有-Wl。争论。
What would make sense in my mind would be this:
我的脑海里会有这样的感觉:
-Wl,-rpath .
This should invoke -rpath linker option with the current directory argument.
这应该调用-rpath链接器选项与当前目录参数。
man gcc:
男人gcc:
-Wl,option
- wl,选择
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'.通过选项作为链接器的选项。如果选项包含逗号,则在逗号分隔为多个选项。可以使用此语法将参数传递给选项。例如,- wl、地图、输出。地图通过地图输出。映射到链接器。当使用GNU链接器时,您也可以使用“-Wl,-Map=output.map”得到相同的效果。
man ld:
男人ld:
-rpath=dir
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;
向运行时库搜索路径添加一个目录。这是在将一个ELF可执行文件与共享对象链接时使用的。所有的-rpath参数被连接并传递给运行时链接器,它使用它们在运行时定位共享对象。-rpath选项也用于定位在链接中显式包含的共享对象所需的共享对象;
4 个解决方案
#1
191
The -Wl,xxx
option for gcc passes a comma-separated list of tokens as a space-separated list of arguments to the linker. So
gcc的-Wl,xxx选项将一个逗号分隔的标记列表传递给链接器。所以
gcc -Wl,aaa,bbb,ccc
eventually becomes a linker call
最终成为一个链接器。
ld aaa bbb ccc
In your case, you want to say "ld -rpath .
", so you pass this to gcc as -Wl,-rpath,.
Alternatively, you can specify repeat instances of -Wl
:
在您的例子中,您想说“ld -rpath”,所以您将它传递到gcc as -Wl,-rpath。或者,您可以指定-Wl的重复实例:
gcc -Wl,aaa -Wl,bbb -Wl,ccc
Note that there is no comma between aaa
and the second -Wl
.
注意,在aaa和第二个-Wl之间没有逗号。
Or, in your case, -Wl,-rpath -Wl,.
.
或者,在你的情况下,-Wl,-rpath -Wl,。
#2
52
You could also write
你也可以写
-Wl,-rpath=.
To get rid of that pesky space. It's arguably more readable than adding extra commas (it's exactly what gets passed to ld).
为了摆脱讨厌的空间。它比添加额外的逗号更容易阅读(这正是传递给ld的内容)。
#3
29
One other thing. You may need to specify the -L option as well - eg
另一件事。您可能需要指定- l选项,如。
-Wl,-rpath,/path/to/foo -L/path/to/foo -lbaz
or you may end up with an error like
或者你可能会得到一个类似的错误。
ld: cannot find -lbaz
#4
7
The man page makes it pretty clear. If you want to pass two arguments (-rpath
and .
) to the linker you can write
这个人的页面非常清楚。如果您想要传递两个参数(-rpath和.)到链接器,您可以写入。
-Wl,-rpath,.
or alternatively
或者
-Wl,-rpath -Wl,.
The arguments -Wl,-rpath .
you suggested do NOT make sense to my mind. How is gcc supposed to know that your second argument (.
) is supposed to be passed to the linker instead of being interpreted normally? The only way it would be able to know that is if it had insider knowledge of all possible linker arguments so it knew that -rpath
required an argument after it.
参数- wl,rpath。你的建议对我来说毫无意义。gcc应该如何知道您的第二个参数(.)应该被传递给链接器而不是通常的解释?唯一能知道的方法是,如果它对所有可能的链接器参数都有内部知识,那么它就知道-rpath需要在它之后进行论证。
#1
191
The -Wl,xxx
option for gcc passes a comma-separated list of tokens as a space-separated list of arguments to the linker. So
gcc的-Wl,xxx选项将一个逗号分隔的标记列表传递给链接器。所以
gcc -Wl,aaa,bbb,ccc
eventually becomes a linker call
最终成为一个链接器。
ld aaa bbb ccc
In your case, you want to say "ld -rpath .
", so you pass this to gcc as -Wl,-rpath,.
Alternatively, you can specify repeat instances of -Wl
:
在您的例子中,您想说“ld -rpath”,所以您将它传递到gcc as -Wl,-rpath。或者,您可以指定-Wl的重复实例:
gcc -Wl,aaa -Wl,bbb -Wl,ccc
Note that there is no comma between aaa
and the second -Wl
.
注意,在aaa和第二个-Wl之间没有逗号。
Or, in your case, -Wl,-rpath -Wl,.
.
或者,在你的情况下,-Wl,-rpath -Wl,。
#2
52
You could also write
你也可以写
-Wl,-rpath=.
To get rid of that pesky space. It's arguably more readable than adding extra commas (it's exactly what gets passed to ld).
为了摆脱讨厌的空间。它比添加额外的逗号更容易阅读(这正是传递给ld的内容)。
#3
29
One other thing. You may need to specify the -L option as well - eg
另一件事。您可能需要指定- l选项,如。
-Wl,-rpath,/path/to/foo -L/path/to/foo -lbaz
or you may end up with an error like
或者你可能会得到一个类似的错误。
ld: cannot find -lbaz
#4
7
The man page makes it pretty clear. If you want to pass two arguments (-rpath
and .
) to the linker you can write
这个人的页面非常清楚。如果您想要传递两个参数(-rpath和.)到链接器,您可以写入。
-Wl,-rpath,.
or alternatively
或者
-Wl,-rpath -Wl,.
The arguments -Wl,-rpath .
you suggested do NOT make sense to my mind. How is gcc supposed to know that your second argument (.
) is supposed to be passed to the linker instead of being interpreted normally? The only way it would be able to know that is if it had insider knowledge of all possible linker arguments so it knew that -rpath
required an argument after it.
参数- wl,rpath。你的建议对我来说毫无意义。gcc应该如何知道您的第二个参数(.)应该被传递给链接器而不是通常的解释?唯一能知道的方法是,如果它对所有可能的链接器参数都有内部知识,那么它就知道-rpath需要在它之后进行论证。