首页 文章

如何链接到标准库的特定版本(使用gcc)

提问于
浏览
0

我已经将GCC 3.4安装到/opt/gcc-3.4,并且我用它来编译与GCC 4不兼容的遗留代码 . 这也意味着旧版本的C()标准库,binutils和实用程序库 .

它适用于某些库,但在编译libtiff时失败,因为它在/ usr / lib中获取系统库(参见下面的输出) . 这可能是一个autotools / configure问题,但我不确定 . 我找不到配置开关或环境变量,我宁愿不修改我的系统/usr/lib/libc.so .

那么如何确保它链接到/opt/gcc-3.4.4/lib中的标准库,并完全忽略/ lib和/ usr / lib?

make的输出(摘录):

libtool:link:g -shared -nostdlib /usr/lib/crti.o /opt/gcc-3.4.3/lib/gcc/i686-pc-linux-gnu/3.4.3/crtbeginS.o .libs / tif_stream .o -Wl, - 整个档案../port/.libs/libport.a -Wl, - no-whole-archive -Wl,-rpath -Wl,/ home / jason / d0src34 / prereq / tiff- 3.9.4 / libtiff / .libs -Wl,-rpath -Wl,/ opt / gcc-3.4.3 / lib -Wl,-rpath -Wl,/ home / jason / d0src34 / prereq / usr / lib -Wl, - rpath -Wl,/ opt / gcc-3.4.3 / lib ../libtiff/.libs/libtiff.so -L / usr / lib /usr/lib/libjpeg.so -lz -L / opt / gcc-3.4 . 3 / lib / gcc / i686-pc-linux-gnu / 3.4.3 -L / opt / gcc-3.4.3 / lib / gcc / i686-pc-linux-gnu / 3.4.3 /../../ ../opt/gcc-3.4.3/lib/libstdc .so -L / home / jason / Downloads / gcc-3.4.3 / build / i686-pc-linux-gnu / libstdc -v3 / src -L / home /jason/Downloads/gcc-3.4.3/build/i686-pc-linux-gnu/libstdc -v3 / src / .libs -L / home / jason / Downloads / gcc-3.4.3 / build / gcc -lm - lc -lgcc_s /opt/gcc-3.4.3/lib/gcc/i686-pc-linux-gnu/3.4.3/crtendS.o /usr/lib/crtn.o -Wl,-soname -Wl,libtiffxx.so .3 -o .libs / libtiffxx.so.3.9.4 /home/jason/d0src34/prereq/usr/bin/ld:/usr/lib/libc.so:file form不承认;作为链接器脚本处理/home/jason/d0src34/prereq/usr/bin/ld:/usr/lib/libc.so:5:解析错误

1 回答

  • 0

    我找到了一个(hackish)回答我自己的问题:

    我一直在使用binutils 2.15,因为后来的版本与GCC 3.4不兼容 . 在更新的版本中,/ usr / lib / libc.so的格式已更改,旧的binutils无法解析它 .

    我暂时注释掉了最后一行(带有“GROUP”),并编译了我的代码:

    /* GNU ld script
       Use the shared library, but some functions are only in
       the static library, so try that secondarily.  */
    OUTPUT_FORMAT(elf32-i386)
    /* GROUP ( /lib/libc.so.6 /usr/lib/libc_nonshared.a  AS_NEEDED ( /lib/ld-linux.so.2 ) ) */
    

    但是,我并不满意,因为我很难告诉其他想要使用代码来编辑系统文件的人 . 此外,我不确定我是否已将其链接到正确的glibc版本,因为系统/ usr / lib仍在搜索路径中,因此我无法确定二进制文件是否可以在其他系统上运行 .

相关问题