#include <bfd.h> #include <stdlib.h> bfd *abfd; int main() { bfd_init(); abfd = bfd_openr("/home/mike/Desktop/testFunc/testProg",NULL); return 0; }
我使用以下命令行进行编译:
gcc readInfo.c /usr/lib/libbfd.a -o readInfo
我收到以下错误:
gcc readInfo.c /usr/lib/libbfd.a -o readInfo
/usr/lib/libbfd.a(elflink.o): In function
elf_link_add_object_symbols':
objalloc_free_block’
/build/buildd/binutils-2.21.53.20110810/builddir-single/bfd/../../bfd/elflink.c:4605:
undefined reference to
/build/buildd/binutils-2.21.53.20110810/builddir-single/bfd/../../bfd/elflink.c:4892:
undefined reference to_sch_istable' /usr/lib/libbfd.a(elflink.o): In
bfd_elf_size_dynamic_sections’:
function
/build/buildd/binutils-2.21.53.20110810/builddir-single/bfd/../../bfd/elflink.c:6048:
undefined reference tolbasename'
_sch_istable’ collect2: ld returned 1 exit
undefined reference to
status make: * [all] Error 1
还有很多错误,你可以查看here.我确定有一个简单的解释,但它让我难倒了一段时间.
总结到目前为止我所做的事情:
>安装了Ubuntu的干净版本
>安装binutils-dev包
解决方法
gcc readInfo.c -o readInfo -lbfd
尝试使其静态链接时,我遇到了一个新问题:
$gcc readInfo.c /usr/lib/libbfd.a /usr/lib/x86_64-linux-gnu/libc.a -o readInfo /usr/bin/ld.bfd.real: dynamic STT_GNU_IFUNC symbol `strcmp' with pointer equality in `/usr/lib/x86_64-linux-gnu/libc.a(strcmp.o)' can not be used when making an executable; recompile with -fPIE and relink with -pie collect2: ld returned 1 exit status $gcc -fPIE readInfo.c /usr/lib/libbfd.a /usr/lib/x86_64-linux-gnu/libc.a \ -o readInfo /usr/bin/ld.bfd.real: dynamic STT_GNU_IFUNC symbol `strcmp' with pointer equality in `/usr/lib/x86_64-linux-gnu/libc.a(strcmp.o)' can not be used when making an executable; recompile with -fPIE and relink with -pie collect2: ld returned 1 exit status $gcc -fPIE -pie readInfo.c /usr/lib/libbfd.a /usr/lib/x86_64-linux-gnu/libc.a \ -o readInfo /usr/bin/ld.bfd.real: /usr/lib/libbfd.a(opncls.o): relocation R_X86_64_32S against `.rodata' can not be used when making a shared object; recompile with -fPIC /usr/lib/libbfd.a: could not read symbols: Bad value collect2: ld returned 1 exit status $gcc -fPIC -fPIE -pie readInfo.c /usr/lib/libbfd.a \ /usr/lib/x86_64-linux-gnu/libc.a -o readInfo /usr/bin/ld.bfd.real: /usr/lib/libbfd.a(opncls.o): relocation R_X86_64_32S against `.rodata' can not be used when making a shared object; recompile with -fPIC /usr/lib/libbfd.a: could not read symbols: Bad value collect2: ld returned 1 exit status