C 符号查找错误:./libobjdata.so:未定义符号:bfd\u映射\u覆盖\u节

C 符号查找错误:./libobjdata.so:未定义符号:bfd\u映射\u覆盖\u节,c,C,当我编译getsections_dl.c文件时,它总是输出这个错误,这是否意味着我没有链接库 我的编译命令是: gcc getsections_dl.c -L. -ldl -lbfd -o getsections_dl My getsections_dl.c: #include <stdlib.h> #include <string.h> #include <bfd.h> #include <unistd.h> #include <dlfc

当我编译getsections_dl.c文件时,它总是输出这个错误,这是否意味着我没有链接库

我的编译命令是:

gcc getsections_dl.c -L. -ldl -lbfd -o getsections_dl
My getsections_dl.c:

#include <stdlib.h>
#include <string.h>
#include <bfd.h>
#include <unistd.h>
#include <dlfcn.h>

extern void dump_sections(bfd *abfd);
#define rdtsc(x)    __asm__ __volatile__("rdtsc \n\t" : "=A" (*(x)))



// the following function is a tweaked version of the itoa functions
// that can be found in either objsym.c or objsect.c
char* lltoa(long long int val, int base) {
  if (val == 0x0) {
   static char zero[] = "0";
   return &zero[0];
  }
  static char buf[64] = {0};
  int i = 60;
  for(; val && i ; --i, val /= base)
    buf[i] = "0123456789abcdef"[val % base];
  return &buf[i+1];
}


int main(int argc, char *argv[]) {
  bfd *obj;
  void *handle;
  unsigned long long start, finish;  
  void (*func)(bfd *);

  bfd_init();

  obj = bfd_openr(argv[1], "elf32-i386");
  if (!obj) {
    bfd_perror("open failure\n");
    return 0;
  }

  rdtsc(&start);

  if (!strcmp(argv[2], "RTLD_LAZY"))
    handle = dlopen("./libobjdata.so", RTLD_LAZY);
  else
    handle = dlopen("./libobjdata.so", RTLD_NOW);

  rdtsc(&finish);

  bfd_check_format(obj, bfd_object);


  //compute the cycles
  write(1, "time: ", strlen("time: "));
  int t = (finish-start)/2793;
  write(1, lltoa(t, 10), strlen(lltoa(t, 10)));
  write(1, " cycles/MHz\n\n", strlen(" cycles/MHz\n\n"));



  func = dlsym(handle, "dump_sections");
  // bfd_map_over_sections(obj, func2, NULL);
  dump_sections(obj);
  dlclose(handle);

  return 0;
}
#包括
#包括
#包括
#包括
#包括
外部空心倾倒区(bfd*abfd);
#定义rdtsc(x)\ asm\uuuuuuuuuuuuuuuuuuuuuuuuuuuuu volatile\uuuuu(“rdtsc\n\t”:“=A”(*(x)))
//以下函数是itoa函数的调整版本
//可以在objsym.c或objsect.c中找到
字符*lltoa(长整型值,整型基){
如果(val==0x0){
静态字符0[]=“0”;
返回&零[0];
}
静态字符buf[64]={0};
int i=60;
对于(;val&&i;--i,val/=base)
buf[i]=“0123456789abcdef”[val%基数];
返回和基本单位[i+1];
}
int main(int argc,char*argv[]){
bfd*obj;
无效*手柄;
无符号长-长开始、结束;
无效(*func)(bfd*);
bfd_init();
obj=bfd_openr(argv[1],“elf32-i386”);
如果(!obj){
bfd_perror(“打开故障”);
返回0;
}
rdtsc(&start);
if(!strcmp(argv[2],“RTLD_LAZY”))
handle=dlopen(“./libobjdata.so”,RTLD_-LAZY);
其他的
handle=dlopen(“./libobjdata.so”,RTLD_NOW);
rdtsc(表面处理);
bfd_检查_格式(obj,bfd_对象);
//计算周期
写(1,“时间:”,斯特伦(“时间:”);
int t=(完成-开始)/2793;
写(1,lltoa(t,10),strlen(lltoa(t,10));
写入(1,“周期/MHz\n\n”,strlen(“周期/MHz\n\n”);
func=dlsym(手柄,“转储段”);
//bfd_映射_到_部分(obj,func2,NULL);
倾倒区(obj);
dlclose(手柄);
返回0;
}
以及我的库C文件objsect.C(这是执行类似于objdump()的操作):

#包括
#包括
#包括
#包括
无效转储_段(bfd*abfd、asection*段、无效*obj)
{
//每个目标字节的八位字节数
//无符号整数opb=bfd_八位字节/u字节(abfd);
字符*itoa(int val,int base){
如果(val==0x0){
静态字符0[]=“0”;
返回&零[0];
}
静态字符buf[32]={0};
int i=30;
对于(;val&&i;--i,val/=base)
buf[i]=“0123456789abcdef”[val%基数];
返回和基本单位[i+1];
}
//写(1,“节:”,斯特伦(“节:”);
写(1,节->名称,strlen(节->名称));
写(1,“\t”,strlen(“\t”);
写入(1,itoa(部分->vma,16),strlen(itoa(部分->vma,16));
写(1,“\t”,strlen(“\t”);
写入(1,itoa(部分->rawsize,16),strlen(itoa(部分->rawsize,10));
写(1,“\t”,strlen(“\t”);
写入(1,itoa(部分->大小,16),strlen(itoa(部分->大小,10));
写(1,“\t”,strlen(“\t”);
写入(1,itoa(部分->文件位置,16),strlen(itoa(部分->文件位置,16));
写入(1,“\n”,strlen(“\n”);
}
空卸料段(bfd*abfd)
{
写(1,“姓名”,strlen(“姓名”);
写入(1,“大小\t”,strlen(“大小\t”);
写(1,“VMA\tt”,strlen(“VMA\t”);
书写(1,“LMA\t”,strlen(“LMA\t”);
注销(1,“注销”,strlen(“注销”);
写入(1,“Algn\n”,strlen(“Algn\n”);
//对于abfd中的每个节,调用dump_section_headers()
bfd_映射_到_段(abfd,转储_段,空);
}

它输出了哪个错误?/getsections\u dl:符号查找错误:./libobjdata.so:未定义的符号:bfd\u map\u over\u sections@polkovnikov.ph您的两个文件都不包含
bfd\u map\u over\u sections
的定义。显然你需要在某个地方定义它。在
*.lib/*.a
*.c
文件中。它不应该是一个bfd函数,我已经在objsect.c@polkovinkov.phbfd.h中包含了bfd.h。
bfd.h
文件是一个包含声明的头文件。只需打开该文件并搜索
bfd\u map\u over\u部分
。你看到那边的密码了吗?
#include <bfd.h>
#include <stdio.h>
#include <unistd.h>
#include <string.h>

void dump_section(bfd *abfd, asection *section, void *obj)
{
    // Number of octets per target byte
    //unsigned int opb = bfd_octets_per_byte(abfd); 


char* itoa(int val, int base) {
  if (val == 0x0) {
   static char zero[] = "0";
   return &zero[0];
  }
  static char buf[32] = {0};
  int i = 30;
  for(; val && i ; --i, val /= base)
    buf[i] = "0123456789abcdef"[val % base];
  return &buf[i+1];
}



//write(1, "Section:", strlen("Section:"));
write(1, section->name, strlen(section->name));
write(1, " \t", strlen(" \t"));
write(1, itoa(section->vma, 16), strlen(itoa(section->vma, 16)));
write(1, " \t", strlen(" \t"));
write(1, itoa(section->rawsize, 16), strlen(itoa(section->rawsize, 10)));
write(1, " \t", strlen(" \t"));
write(1, itoa(section->size, 16), strlen(itoa(section->size, 10)));
write(1, " \t", strlen(" \t"));
write(1, itoa(section->filepos, 16), strlen(itoa(section->filepos, 16)));
write(1, " \n", strlen(" \n"));
}

void dump_sections(bfd *abfd)
{

    write(1, "Name\t", strlen("Name\t"));

    write(1, "Size\t", strlen("Size\t"));

    write(1, "VMA\tt", strlen("VMA\t"));
    write(1, "LMA\t", strlen("LMA\t"));
    write(1, "File off\t", strlen("File off\t"));
    write(1, "Algn\n", strlen("Algn\n"));

// For each section in abfd, call dump_section_headers()
    bfd_map_over_sections(abfd, dump_section, NULL);
}