1

In FreeBSD 10.3 there are 2 libelf.h, /usr/include/libelf.h and /usr/local/include/libelf/libelf.h. And they have different defines, such as enum Elf_Cmd.

Also there are 2 libdwarf.h, /usr/include/libdwarf.h and /usr/local/include/libdwarf.h. And they have different defines, such as dwarf_init().

Why? What's the difference? Which one should I use?

=== update ===

Thanks for forquare, now I know that there are 2 libraries both named libelf. I have tried them, and they worked both. However I still have problom with libdwarf.

Code:

#include <stdio.h>
#include <fcntl.h>
#include <libdwarf.h>

int main()
{
    int fd = open("memleax", O_RDONLY);

    Dwarf_Debug dbg;
    Dwarf_Error error;
#if USR_LOCAL
    int res = dwarf_init(fd, DW_DLC_READ, 0, 0, &dbg, &error);
    if(res != DW_DLV_OK) {
            printf("dwarf_init error: %s\n", dwarf_errmsg(error));
            return -1;
    }
#else
    int res = dwarf_init(fd, DW_DLC_READ, &dbg, &error);
    if(res != DW_DLV_OK) {
            printf("dwarf_init error: %s\n", dwarf_errmsg(&error));
            return -1;
    }
#endif

If using system-lib:

cc  debugline.c -o debugline   -lelf -ldwarf

it goes wrong with:

dwarf_init error: ELF error : I/O error [dwarf_init(738)]

If using usr-local-lib:

cc -D USR_LOCAL -I /usr/local/include/ debugline.c -o debugline -L /usr/local/lib/ -lelf -ldwarf

it goes wrong with:

dwarf_init error: DW_DLE_ELF_BEGIN_ERROR 27 a call to elf_begin(... ELF_C_READ_MMAP... ) failed

How should I use libdwarf?

=== update

Ok, I know....

There are 2 libdwarf. I should ignore system-lib, and install the non-system-lib by pkg, and use it.

There are 2 libelf. I should use the system-lib, and can't install the non-system-lib by pkg.

  • What is the output of pkg which /usr/local/include/libdwarf.h ? – Mark Plotnick May 29 '16 at 23:05
  • /usr/local/include/libdwarf.h was installed by package libdwarf-20130207 – Bingzheng Wu May 30 '16 at 14:07
2

The one located in /usr/include/libelf.h is included with FreeBSD while /usr/local/include/libelf/libelf.h has been installed by you/the system admin most likely as part of a dependency for another package—perhaps the one included in base wasn't at the correct version, or maybe the one installed is from a difference source altogether.

You can use either, but if you move to a system that doesn't have /usr/local/include/libelf/libelf.h you will need to install it via ports or pkg.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.