LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 12-04-2007, 02:36 AM   #1
imbeyondboredom
LQ Newbie
 
Registered: Dec 2007
Posts: 2

Rep: Reputation: 0
undefined reference to `bfd_openr'


Hey guys,

I've been racking my brain against this one and I can't figure it out. So I'm trying to compile this code which should make signatures for various methods and such in libc.a but I keep getting this error:

/tmp/ccUn3VTU.o: In function `main':
fprints.c.text+0x21c): undefined reference to `bfd_openr'
fprints.c.text+0x269): undefined reference to `bfd_check_format'
fprints.c.text+0x284): undefined reference to `bfd_check_format_matches'
collect2: ld returned 1 exit status

This is when I'm compiling the program using this command:
g++ -lssl -lbfd fprints.c

I thought that maybe because this code is like 6 years old that it simply was using bfd wrong but since it's an undefined reference then the usage should be valid right?

Any input would be greatly appreciated on this matter.
 
Old 12-04-2007, 02:42 AM   #2
imbeyondboredom
LQ Newbie
 
Registered: Dec 2007
Posts: 2

Original Poster
Rep: Reputation: 0
More information...

Just in case this helps I'm including the file which I'm trying to compile... and for the record if anyone knows of some different methods to achieve the same result then please let me know because I just need to get the file that this is supposed to make to work with my other software.

Code:
/*
   fenris - program execution path analysis tool
   ---------------------------------------------

   Copyright (C) 2001, 2002 by Bindview Corporation
   Portions copyright (C) 2001, 2002 by their respective contributors
   Developed and maintained by Michal Zalewski <lcamtuf@coredump.cx>

   This program is free software; you can redistribute it and/or modify
   it under the terms of the GNU General Public License as published by
   the Free Software Foundation; either version 2 of the License, or
   (at your option) any later version.

   This program is distributed in the hope that it will be useful,
   but WITHOUT ANY WARRANTY; without even the implied warranty of
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   GNU General Public License for more details.

   You should have received a copy of the GNU General Public License
   along with this program; if not, write to the Free Software
   Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.

*/

#include <string.h>
#include <stdlib.h>
#include <unistd.h>
#include <stdio.h>
#include <fcntl.h>
#include <bfd.h>
#include <libiberty.h>

#include "libfnprints.h"

#include "config.h"

unsigned char buf[SIGNATSIZE+4];

#define CODESEG (((unsigned int)buf) >> 24)

unsigned int result[4];
MD5_CTX kuku;

int main(int argc,char* argv[]) {
  int summ=0;
  asymbol** syms;
  int size,symcnt,i,off;
  bfd* b;

  if (argc-2) { 
    fprintf(stderr,"function signatures for fenris -- <lcamtuf@coredump.cx>\n");
    fprintf(stderr,"Usage: %s elf_object\n",argv[0]);
    exit(1);
  }

  b = bfd_openr(argv[1],0);
  if (!b) { fprintf(stderr,"bfd_openr failed\n"); exit(1); }

  bfd_check_format(b,bfd_archive);
  bfd_check_format_matches(b,bfd_object,0);

  if ((bfd_get_file_flags(b) & HAS_SYMS) == 0) {
    if (!getenv("FANCY")) fprintf(stderr,"No symbols.\n");
      else fprintf(stderr,"EMPTY");
    exit(1);
  }

  size=bfd_get_symtab_upper_bound(b);
  syms=(asymbol**)malloc(size);
  symcnt=bfd_canonicalize_symtab(b,syms);

  for (i=0;i<symcnt;i++) {

    if (syms[i]->flags & BSF_FUNCTION) {
      char name[500],*fiu;

      strcpy(name,(char*)(bfd_asymbol_name(syms[i])));
      if ((fiu=strstr(&name[2],"__"))) 
        if (*(fiu-1)!='_') *fiu=0;

      if ((fiu=strchr(name+1,'@'))) *fiu=0;

      if (!strlen(name)) continue;

      off=syms[i]->value; 
      if (syms[i]->section) off+=syms[i]->section->filepos;

      

      { unsigned int f;
        f=open(argv[1],O_RDONLY);
        lseek(f,off,SEEK_SET);
        summ++;
        bzero(buf,sizeof(buf));
        read(f,buf,SIGNATSIZE);

        f=fnprint_compute(buf,CODESEG);

        if (f!=0xA120AD5C) { // Ignore only NOPs
          printf("[%s+%d] %s ",argv[1],off,name);
          printf("%08X\n",f);
        }
      }
    }
  }

  if (getenv("FANCY")) fprintf(stderr,"%d function%s",summ,summ==1?"":"s");
  else fprintf(stderr,"--> %s: done (%d function%s)\n",argv[1],summ,
               summ==1?"":"s");

  return 0;

}
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Undefined reference, why? george_mercury Programming 4 05-07-2009 12:15 AM
Undefined reference to: ashlesha Programming 5 11-08-2006 01:07 PM
undefined reference vkmgeek Programming 1 05-11-2006 06:37 AM
Undefined Reference ChemicalBurn Programming 2 02-14-2005 03:01 AM
undefined reference mp4-10 Programming 3 01-25-2005 12:38 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 11:14 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration