c - 无法编译 GNU-EFI 程序
问题描述
我已经按照一个教程来研究 UEFI shell 问题是当我尝试编译时我得到了这个我不明白的
ERROR:`hello.c: In function ‘efi_main’:
hello.c:8:10: warning: passing argument 1 of ‘Print’ from incompatible pointer type [-Wincompatible-pointer-types]
Print(L"Hi,,,");
^~~~~~~~
In file included from hello.c:2:0:
/usr/local/include/efi/efilib.h:503:1: note: expected ‘const CHAR16 * {aka const short unsigned int *}’ but argument is of type ‘int *’
Print (
^~~~~
/usr/lib/gcc/x86_64-linux-gnu/7/../../../x86_64-linux-gnu/Scrt1.o: In function `_start':
(.text+0x20): undefined reference to `main'
/tmp/ccGlbBgD.o: In function `efi_main':
hello.c:(.text+0x1f): undefined reference to `InitializeLib'
hello.c:(.text+0x30): undefined reference to `Print'
collect2: error: ld returned 1 exit status`
教程网址:“ https://www.rodsbooks.com/efi-programming/hello.html ”
顺便说一句,我是 C 编程新手
编辑:我尝试使用 gcc 版本 7.4.0 和 5.5.0 来编译程序加上我通过“sudo apt-get install gnu-efi”安装了 gnu-efi,并从教程中对代码进行了更改这里是代码
#include <efi/efi.h>
#include <efi/efilib.h>
EFI_STATUS
EFIAPI
efi_main (EFI_HANDLE ImageHandle, EFI_SYSTEM_TABLE *SystemTable) {
InitializeLib(ImageHandle, SystemTable);
Print(L"Hi,,,");
return EFI_SUCCESS;
}
我试过的命令
海合会 v7.4.0gcc hello.c -I /usr/include/efi/x86_64
海合会 v5.5.0gcc-5 hello.c -I /usr/include/efi/x86_64
解决方案
出现错误是因为您在编译 efi 程序时没有使用您应该拥有的编译器选项。显示的错误来自缺少-fshort-wchar
选项。未定义的引用来自未链接到 efi 库。来自undefined reference to 'main'
不使用-shared
编译选项。
您链接的站点显示了有关如何编译程序的示例生成文件。该站点还对用于编译程序的一些编译标志进行了简短说明。最简单的方法是使用该makefile。按照它来编译efi程序。
另一种方法是手动从 makefile 中提取编译和链接器标志,并使用适当的编译选项进行编译。
推荐阅读
- apache - mod_rewrite 编码后的url?
- javascript - Vue.Js:如何在 JSON 中循环子对象
- django - 如何从反向外键 Django 序列化程序(一对多)中获取所有相关对象?
- javascript - 为什么 WebGL 使用 GLSL 代码块的字符串表示?
- xamarin.forms - 退出前在主详细信息页面上确认
- sql - 多选时如何过滤掉重复的列(SQL Server)
- c++ - 计算两个 uint8_t 变量之间差异的最快方法是什么?
- android - 错误:格式字符串不是字符串文字(可能不安全)[-Werror,-Wformat-security]
- css - 具有响应宽度和连续两个按钮的输入
- regex - GNU Octave 的 regexprep 可能错误地编号可选组