Compile Errors Using Bfd.H on Linux

Compile Errors using bfd.h on Linux

Do you need to statically link your program?

It compiles and runs without error if you dynamically link it instead:

gcc readInfo.c -o readInfo -lbfd

I've run into a new problem when trying to make it statically linked:

$ 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

binutils/bfd.h wants config.h now?

Well, the most correct way of using the header is to use autotools in your package as well. Some people are simply stubborn and I don't think you can do much about it.

An alternative is to work-around the check, by defining the macros it is using:

#define PACKAGE 1
#define PACKAGE_VERSION 1

Of course, if you are already defining those, you may as well set them to some reasonable values like:

#define PACKAGE "your-program-name"
#define PACKAGE_VERSION "1.2.3"

and use them for your program. You'll usually going to use something like that anyway at some point to keep the versions consistent.

This should be enough if you're using a standards-compliant compiler because then the __STDC__ macro will be declared and everything will go on just fine. Well, as long as the headers you're using won't require more autoconf-generated defines.

For example, if you wanted to use plugin-api.h, you'd actually have to handle checking for stdint.h and inttypes.h...

BFD Library not found

g++ -D_GLIBCXX_USE_CXX11_ABI=0 loader.cc

You didn't tell g++ to 'link with libbfd',
so in 'link' phase, it couldn't find the functions provided by libbfd.

I guess you need g++ -D_GLIBCXX_USE_CXX11_ABI=0 -lbfd loader.cc.

bfd library not found error when configuring Oprofile

Seems like you are missing a library. This command installs bfd library for me:

sudo apt-get install binutils-dev

Errors while trying to compile with external libraries

You are getting a linker error simply because you are not referencing the library when compiling the test source file. It needs to be something like:

g++ mimetic.cpp -l<libraryname>

The reason it compiles when you add the braces is that you are really declaring a function called 'me' that returns a MimeEntry. While it compiles, it does not do what you want.



Related Topics



Leave a reply



Submit