链接错误:在RHEL 6.0上使用gcc 4.5.2 - 我不明白

时间:2012-01-04 21:05:57

标签: linux gcc linker

这是命令和错误。

gcc --shared  \
        -m64 \
        -shared-libgcc \
        -Wl,--whole-archive ./release64/*.a
/usr/lib64/libc_nonshared.a(elf-init.oS): In function `__libc_csu_init':
(.text+0x1d): undefined reference to `__init_array_end'
/usr/bin/ld: /usr/lib64/libc_nonshared.a(elf-init.oS): relocation R_X86_64_PC32 against undefined hidden symbol `__init_array_end' can not be used when making a shared object
/usr/bin/ld: final link failed: Bad value
collect2: ld returned 1 exit status
make: *** [build] Error 1

这是什么意思?

1 个答案:

答案 0 :(得分:6)

留下"悬挂" --whole-archive选项,您欺骗GCC尝试将没有-fPIC(从libc_nonshared.a)编译的代码链接到共享库。不要。这样做:

gcc -shared ... -Wl,--whole-archive release64/*.a -Wl,--no-whole-archive