我想尝试在c++中制作一个小的(U(EFI引导程序,但是,当我尝试编译我的代码(使用g++(时,会出现以下错误:
boot.cpp: In function ‘EFI_STATUS efi_main(EFI_HANDLE, EFI_SYSTEM_TABLE*)’:
boot.cpp:9:9: error: invalid conversion from ‘const wchar_t*’ to ‘const CHAR16*’ {aka ‘const short unsigned int*’} [-fpermissive]
9 | Print(L"Hello, world!n");
| ^~~~~~~~~~~~~~~~~~
| |
| const wchar_t*
In file included from boot.cpp:2:
/usr/include/efi/efilib.h:504:24: note: initializing argument 1 of ‘UINTN Print(const CHAR16*, ...)’
504 | IN CONST CHAR16 *fmt,
我使用了这个命令(我在Ubuntu WSL2上工作(:
g++ boot.cpp -mno-red-zone -ffreestanding -fshort-wchar -nostdlib -e efi_main -Wl,-dll -shared -Wl,--subsystem,10 -c -I/usr/include/efi/ -I/usr/include/efi/x86_64/
这是我的代码:
#include <efi.h>
#include <efilib.h>
EFI_STATUS
EFIAPI
efi_main (EFI_HANDLE ImageHandle, EFI_SYSTEM_TABLE *SystemTable)
{
InitializeLib(ImageHandle, SystemTable);
Print(L"Hello, world!n");
return EFI_SUCCESS;
}
编辑:如果我从";你好,世界;,给我这个错误:
boot.cpp: In function ‘EFI_STATUS efi_main(EFI_HANDLE, EFI_SYSTEM_TABLE*)’:
boot.cpp:9:9: error: cannot convert ‘const char*’ to ‘const CHAR16*’ {aka ‘const short unsigned int*’}
9 | Print("Hello, world!n");
| ^~~~~~~~~~~~~~~~~
| |
| const char*
In file included from boot.cpp:2:
/usr/include/efi/efilib.h:504:24: note: initializing argument 1 of ‘UINTN Print(const CHAR16*, ...)’
504 | IN CONST CHAR16 *fmt,
编辑2:如果我在hello world(u"hello,world\n&"(前面使用u,则会出现以下错误:
boot.cpp: In function ‘EFI_STATUS efi_main(EFI_HANDLE, EFI_SYSTEM_TABLE*)’:
boot.cpp:9:9: error: invalid conversion from ‘const char16_t*’ to ‘const CHAR16*’ {aka ‘const short unsigned int*’} [-fpermissive]
9 | Print(u"Hello, world!n");
| ^~~~~~~~~~~~~~~~~~
| |
| const char16_t*
In file included from boot.cpp:2:
/usr/include/efi/efilib.h:504:24: note: initializing argument 1 of ‘UINTN Print(const CHAR16*, ...)’
504 | IN CONST CHAR16 *fmt,
I解析,使用gcc而不是g++,并强制转换为CHAR16*