我有一堆使用 g++ 在 C++ 中在 Linux 上开发的软件。该代码可在 Ubuntu 12.04 和 CentOS 5 上编译和运行。我们有一些旧服务器仍在运行 CentOS 5。目前我为这两种操作系统进行编译。我想开始使用一些 C++11 特性。这些在 Ubuntu 12.04 上受支持,但在 CentOS 5 上不受支持。
我正在尝试在 Ubuntu 上为 CentOS 生成可执行文件。为此,我将所有可执行文件与
-Wl,-rpath,/home/arcamax/lib
这应该告诉它在标准位置之前在 /home/arcamax/lib 中查找共享库。然后我在 Ubuntu 机器上使用“ldd”来构建所需库的列表,并将这些库复制到 CentOS 机器上的 /home/arcamax/lib 中。当我尝试在 CentOS 机器上运行程序时,我得到:
当我在 CentOS5 机器上运行 ldd 时,我得到如下输出:
libcrypto.so.1.0.0 => /home/arcamax/lib/libcrypto.so.1.0.0 (0x00002b3557f54000) libpq.so.5 => /home/arcamax/lib/libpq.so.5 (0x00002b355831c000) libstdc++.so.6 => /home/arcamax/lib/libstdc++.so.6 (0x00002b3558548000) libm.so.6 => /home/arcamax/lib/libm.so.6 (0x00002b3558849000) libgcc_s.so.1 => /home/arcamax/lib/libgcc_s.so.1 (0x00002b3558b43000) libc.so.6 => /home/arcamax/lib/libc.so.6 (0x00002b3558d59000) libpthread.so.0 => /home/arcamax/lib/libpthread.so.0 (0x00002b3559117000) libdl.so.2 => /home/arcamax/lib/libdl.so.2 (0x00002b3559334000) libz.so.1 => /home/arcamax/lib/libz.so.1 (0x00002b3559538000) libssl.so.1.0.0 => /home/arcamax/lib/libssl.so.1.0.0 (0x00002b3559750000) libkrb5.so.3 => /home/arcamax/lib/libkrb5.so.3 (0x00002b35599ac000) libcom_err.so.2 => /home/arcamax/lib/libcom_err.so.2 (0x00002b3559c7a000) libgssapi_krb5.so.2 => /home/arcamax/lib/libgssapi_krb5.so.2 (0x00002b3559e7f000) libldap_r-2.4.so.2 => /home/arcamax/lib/libldap_r-2.4.so.2 (0x00002b355a0bd000) /lib64/ld-linux-x86-64.so.2 (0x00000035aa800000) libk5crypto.so.3 => /home/arcamax/lib/libk5crypto.so.3 (0x00002b355a30d000) libkrb5support.so.0 => /home/arcamax/lib/libkrb5support.so.0 (0x00002b355a535000) libkeyutils.so.1 => /home/arcamax/lib/libkeyutils.so.1 (0x00002b355a73d000) libresolv.so.2 => /home/arcamax/lib/libresolv.so.2 (0x00002b355a942000) liblber-2.4.so.2 => /home/arcamax/lib/liblber-2.4.so.2 (0x00002b355ab5e000) libsasl2.so.2 => /home/arcamax/lib/libsasl2.so.2 (0x00002b355ad6c000) libgssapi.so.3 => /home/arcamax/lib/libgssapi.so.3 (0x00002b355af88000) libgnutls.so.26 => /home/arcamax/lib/libgnutls.so.26 (0x00002b355b1c6000) libgcrypt.so.11 => /home/arcamax/lib/libgcrypt.so.11 (0x00002b355b482000) libheimntlm.so.0 => /home/arcamax/lib/libheimntlm.so.0 (0x00002b355b701000) libkrb5.so.26 => /home/arcamax/lib/libkrb5.so.26 (0x00002b355b908000) libasn1.so.8 => /home/arcamax/lib/libasn1.so.8 (0x00002b355bb8e000) libhcrypto.so.4 => /home/arcamax/lib/libhcrypto.so.4 (0x00002b355be2f000) libroken.so.18 => /home/arcamax/lib/libroken.so.18 (0x00002b355c063000) libtasn1.so.3 => /home/arcamax/lib/libtasn1.so.3 (0x00002b355c278000) libp11-kit.so.0 => /home/arcamax/lib/libp11-kit.so.0 (0x00002b355c48a000) libgpg-error.so.0 => /home/arcamax/lib/libgpg-error.so.0 (0x00002b355c69c000) libwind.so.0 => /home/arcamax/lib/libwind.so.0 (0x00002b355c8a0000) libheimbase.so.1 => /home/arcamax/lib/libheimbase.so.1 (0x00002b355caca000) libhx509.so.5 => /home/arcamax/lib/libhx509.so.5 (0x00002b355ccd9000) libsqlite3.so.0 => /home/arcamax/lib/libsqlite3.so.0 (0x00002b355cf23000) libcrypt.so.1 => /home/arcamax/lib/libcrypt.so.1 (0x00002b355d1c7000)
请注意,有一个库 /lib64/ld-linux-x86-64.so.2 仍在从系统位置提取。我不知道为什么会这样。当我尝试运行程序时,我得到:
重定位错误:/home/arcamax/lib/libgnutls.so.26:符号时间,版本 GLIBC_2.2.5 未在带有链接时间参考的文件 libc.so.6 中定义
一些程序失败 ldd 并显示以下消息:
不是动态可执行文件
当我尝试运行这些程序时,它们会报告与其他程序相同的错误。