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.
pkg which /usr/local/include/libdwarf.h
?