sách gpt4 ai đã đi

c - 自由 : Undefined Reference for functions

In lại 作者:行者123 更新时间:2023-12-04 03:06:38 28 4
mua khóa gpt4 Nike

我正在尝试使用 Libelf 库来获取有关某些 elf 文件的一些信息。但我不断收到这些“对 [...] 的 undefined reference ”。我从 synaptic 安装了 libelf(也试图从网站上获取),并且 lib 似乎安装正常。

我的代码:

#include 
#include
#include
#include

#include
#include
#include

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);


trả về 0;
}

这是我从终端获得的信息(目前使用的是 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): undefined reference to `elf_end'
collect2: ld returned 1 exit status

làm mới

解决了我在编译过程中将 -lelf 放在我的文件之前的所有问题,除了一个问题。最后一个我只能解决将我的 libelf 更新到新版本(在 Synaptic Manager 上不可用):

wget http://ftp.br.debian.org/debian/pool/main/e/elfutils/libelf-dev_0.153-1_i386.deb
wget http://ftp.br.debian.org/debian/pool/main/e/elfutils/libelf1_0.153-1_i386.deb
sudo dpkg -i libelf-dev_0.153-1_i386.deb libelf1_0.153-1_i386.deb

1 Câu trả lời

您可能需要链接到图书馆。执行此操作的标准方法是:

gcc sample.c -l elf -o sample

这会在标准库目录中搜索 libelf.a,并将该存档中的相关目标文件包含到构建中。假设库已正确安装,libelf.a 或类似名称的文件应该存在。

关于c - 自由 : Undefined Reference for functions,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10591145/

28 4 0
Bài viết được đề xuất: web-services - soap:address 和 http:address
Bài viết được đề xuất: common-lisp - 如何定义一个 &key 参数来取代 Lisp 中的 &optional 参数
Bài viết được đề xuất: semantic-web - 如何使用 Pellet 进行离线推理?
Bài viết được đề xuất: search - 更改 SOLR 默认连接
行者123
Hồ sơ cá nhân

Tôi là một lập trình viên xuất sắc, rất giỏi!

Nhận phiếu giảm giá Didi Taxi miễn phí
Mã giảm giá Didi Taxi
Giấy chứng nhận ICP Bắc Kinh số 000000
Hợp tác quảng cáo: 1813099741@qq.com 6ren.com