ubuntu - 在 Ubuntu 上链接精灵库失败
问题描述
我尝试使用 elf 库在 Ubuntu 上编写一些代码。
但是,它有编译错误,我不知道出了什么问题。
请帮助我,谢谢。
sudo apt-get install libelf-dev
$ gcc -O3 -Wall -lelf test.c
/tmp/ccRqW5Qo.o: In function `main':
test.c:(.text.startup+0xa): undefined reference to `elf_version'
collect2: error: ld returned 1 exit status
这是 test.c 的代码
#include <stdlib.h>
#include <stdio.h>
#include <libelf.h>
int main(void)
{
elf_version(EV_CURRENT);
return 0;
}
解决方案
您对命令行参数使用了错误的顺序。您需要在库之前gcc -O3 -Wall test.c -lelf
列出源文件:会起作用。
推荐阅读
- oracle - 按查询分组 Rising ORA-00934 异常
- r - 使用 gtsummary 包将总 N 的 f 变量添加到 tbl_regression
- flutter - 如何在颤动的TextField中使用多种颜色
- c# - 检测何时进入焦点?
- gradle - 如何排除模块 cxf-rt-transports-http
- dictionary - 如何在 Clojure 中正确“过滤”映射?
- android - Android 重叠其他应用权限
- visual-studio - 我无法为我的项目库单击“打包”来发布它
- r - Biomod 2 Maxent
- android - 执行 exec 命令后 Android 应用程序崩溃