I want to try to make a little (U)EFI bootloader in c++, but, when I try to compile my code (with g++) gives this error:
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,
I used this comand (i working from 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/
Here's my code:
#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;
}
EDIT: If i remove L from "Hello, world\n", gives me this error:
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,
EDIT 2: If i use u in front of hello world (u"Hello,world\n") gives this error:
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 resolve, use gcc instead of g++ and cast to CHAR16*