4.9.9. 链接器 "rpath" 和 "runpath" 功能

Open MPI 和 OpenSHMEM v5.0.x 都由多个相互依赖的库组成。

当从官方发布的压缩包(来自Open MPI官方下载站点)构建时, Open MPI和OpenSHMEM使用以下版本的GNU Autotools进行构建:

  • Autoconf 2.69.0

  • Automake 1.13.4

  • Libtool 2.4.2

这套GNU Autotools工具集通过调用libtool可执行文件,使用-rpath CLI选项来构建Open MPI的库文件和可执行程序。

libtool -rpath ... 的行为在不同系统上存在显著差异。结合编译器、链接器及其他系统级设置,最终可能实现"rpath"行为、"runpath"行为,甚至两种行为都无法实现。

虽然libtool -rpath ..的具体行为超出了本文档的范围,但您可以运行诸如readelf -d ...之类的命令来查明您的Open MPI是使用哪种行为构建的。

例如:

shell$ ./configure --prefix=/opt/openmpi/ ...
...
shell$ make -j 32 all && make install
...
shell$ readelf -d /opt/openmpi/lib/libmpi.so | egrep -i 'rpath|runpath'
 0x000000000000001d (RUNPATH)            Library runpath: [/opt/openmpi/lib]

上述输出表明libmpi.so是使用"runpath"支持构建的,而类似这样的输出:

shell$ readelf -d /opt/openmpi/lib/libmpi.so | egrep -i 'rpath|runpath'
 0x000000000000000f (RPATH)              Library rpath: [/opt/openmpi/lib]

表示libmpi.so是通过"rpath"支持构建的。

注意

如果您希望在构建Open MPI/OpenSHMEM时使用额外的编译器或链接器标志(例如运行路径标志),可以在配置命令行中指定这些标志

例如,如果在您的系统上调用libtool -rpath ...实际上实现了"rpath"行为,而您希望实现"runpath"行为,您可以在调用configure时设置LDFLAGS,如下所示:

shell$ ./configure LDFLAGS=-Wl,--enable-new-dtags ...