2

I have this C code:

asection *s;
s = bfd_get_section_by_name( abfd, "__exported_do_funs" );

Which gives me a compile error:

file.o: In function `do_listdos':
file.c:9500: undefined reference to `bfd_get_section_by_name'
collect2: ld returned 1 exit status

So I've found this is part of binutils I believe, and installed it:

Installed Packages
binutils.i386                     2.17.50.0.6-26.el5        installed
binutils-devel.i386               2.17.50.0.6-26.el5        installed

But still get the same compile error. Am I missing something?

I'm running: gcc version 4.1.2 20080704 (Red Hat 4.1.2-51)

This is in my header file:

#include <bfd.h> /* Eizneckam's BFD Code */

The gcc syntax running is:

/usr/bin/gcc -c -g -g3 -Wall    -DREQUESTS -DSMAUG14  -DTIMEFORMAT -DREGEX file.c

/usr/bin/gcc    -lcrypt -lz -lbfd -liberty -lm -lmysqlclient -lnsl -L/usr/lib/mysql -I/usr/include/mysql/ -o

The lib is found in /usr/lib/libbfd.a

Braiam
  • 1
  • 11
  • 47
  • 78
Zeno
  • 1,769
  • 7
  • 33
  • 61
  • You should be including the .h file that defines this function... – ericbn May 17 '15 at 18:50
  • possible duplicate of [What is an undefined reference/unresolved external symbol error and how do I fix it?](http://stackoverflow.com/questions/12573816/what-is-an-undefined-reference-unresolved-external-symbol-error-and-how-do-i-fix) – ericbn May 17 '15 at 22:15
  • @ericbn I understand the concept and I have the setup correctly from what I understand. I'm not sure why the error is happening. – Zeno May 18 '15 at 01:44
  • You need to put the library references after the object files. So move all the `-lbdf` and similar to the end of your compiler line. – Andrew C May 18 '15 at 02:16
  • possible duplicate of [Unable to link against BFD](http://stackoverflow.com/questions/20915623/unable-to-link-against-bfd) – Zeno May 18 '15 at 02:17

1 Answers1

1

This means it didn't find the implementation of this function.

In your case:

To use the library, include bfd.h and link with libbfd.a.

Reference: http://www.delorie.com/gnu/docs/binutils/bfd_3.html

ericbn
  • 10,163
  • 3
  • 47
  • 55