首页 > 解决方案 > 无法编译 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

标签: clinuxuefi

解决方案


出现错误是因为您在编译 efi 程序时没有使用您应该拥有的编译器选项。显示的错误来自缺少-fshort-wchar选项。未定义的引用来自未链接到 efi 库。来自undefined reference to 'main'不使用-shared编译选项。

您链接的站点显示了有关如何编译程序的示例生成文件。该站点还对用于编译程序的一些编译标志进行了简短说明。最简单的方法是使用该makefile。按照它来编译efi程序。

另一种方法是手动从 makefile 中提取编译和链接器标志,并使用适当的编译选项进行编译。


推荐阅读