无法编译 GNU-EFI 程序

Unable to compile GNU-EFI Program

我已经按照一个教程学习了 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`

教程URL:“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;
}

我试过的命令

GCC v7.4.0gcc hello.c -I /usr/include/efi/x86_64

GCC v5.5.0gcc-5 hello.c -I /usr/include/efi/x86_64

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

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

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

经过一些艰苦的研究后,我让 EFI 程序正常工作,但我没有使用 "Makefile",而是手动完成

使用的命令:

gcc main.c -c -fno-stack-protector -fPIC -fshort-wchar -mno-red-zone -I /usr/include/efi -I /usr/include/efi/x86_64 -DEFI_FUNCTION_WRAPPER -o main.o
ld main.o /usr/lib/crt0-efi-x86_64.o -nostdlib -znocombreloc -T /usr/lib/elf_x86_64_efi.lds -shared -Bsymbolic -L /usr/lib -l:libgnuefi.a -l:libefi.a -o main.so
objcopy -j .text -j .sdata -j .data -j .dynamic -j .dynsym -j .rel -j .rela -j .reloc --target=efi-app-x86_64 main.so main.efi