小编alb*_*amp的帖子

Libelf:函数的未定义参考

我正在尝试使用 Libelf 库来获取一些 elf 文件的信息。但我不断收到这些“未定义的引用[...]”。我从突触安装了 libelf(也尝试从网站获取),并且该库似乎安装正常。

我的代码:

#include <err.h>
#include <fcntl.h>
#include <sysexits.h>
#include <unistd.h>

#include <stdio.h>
#include <stdlib.h>
#include <libelf.h>

int main(int argc, char * argv[]) {
    Elf *elf_file;
    Elf_Kind  elf_kind_file;
    int file_descriptor;

    if((argc!=2)) 
        printf("Argumento em formato nao esperado\n");

    file_descriptor = open(argv[1], O_RDONLY, 0);
    elf_file = elf_begin(file_descriptor, ELF_C_READ, NULL);
    elf_kind_file = elf_kind(elf_file);

    elf_end(elf_file);
    close(file_descriptor);


    return 0;
}
Run Code Online (Sandbox Code Playgroud)

这是我从终端得到的信息(当前使用 Ubuntu 11.4):

gcc sample.c -o sample
/tmp/ccP7v2DT.o: In function `main':
sample.c:(.text+0x57): undefined reference to `elf_begin'
sample.c:(.text+0x67): undefined reference to `elf_kind'
sample.c:(.text+0x77): …
Run Code Online (Sandbox Code Playgroud)

c undefined-reference

3
推荐指数
1
解决办法
4069
查看次数

标签 统计

c ×1

undefined-reference ×1