Kitcha
Kitcha

Reputation: 29

How to solve problem with linking object fies with lld-link?

I have problem with linking data.o (data.c file from gnu efi) and main.o. Im using clang for compiling, lld-ink for linking and gnu-efi as developer envoirenment for uefi.

main.c:

#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;
}

Makefile:

CFLAGS=-target x86_64-unknown-windows -ffreestanding -fshort-wchar -mno-red-zone -I gnu-efi/inc -I gnu-efi/inc/x86_64 -I gnu-efi/inc/protocol
LDFLAGS= -target x86_64-unknown-windows -nostdlib -Wl,-entry:efi_main -Wl,-subsystem:efi_application -fuse-ld=lld-link -shared -Bsymbolic

all:

    clang $(CFLAGS) -c -o main.o src/main.c
    clang $(CFLAGS) -c -o data.o gnu-efi/lib/data.c
    clang $(LDFLAGS) -o bootx64.efi main.o data.o

And here is log in terminal:

clang -target x86_64-unknown-windows -ffreestanding -fshort-wchar -mno-red-zone -I gnu-efi/inc -I gnu-efi/inc/x86_64 -I gnu-efi/inc/protocol -c -o main.o src/main.c
clang -target x86_64-unknown-windows -ffreestanding -fshort-wchar -mno-red-zone -I gnu-efi/inc -I gnu-efi/inc/x86_64 -I gnu-efi/inc/protocol -c -o data.o gnu-efi/lib/data.c
clang -target x86_64-unknown-windows -nostdlib -Wl,-entry:efi_main -Wl,-subsystem:efi_application -fuse-ld=lld-link -shared -Bsymbolic -o bootx64.efi main.o data.o
lld-link: error: undefined symbol: InitializeLib
>>> referenced by main.o:(efi_main)

lld-link: error: undefined symbol: Print
>>> referenced by main.o:(efi_main)

lld-link: error: undefined symbol: LibStubStriCmp
>>> referenced by data.o:(LibStubUnicodeInterface)

lld-link: error: undefined symbol: LibStubMetaiMatch
>>> referenced by data.o:(LibStubUnicodeInterface)

lld-link: error: undefined symbol: LibStubStrLwrUpr
>>> referenced by data.o:(LibStubUnicodeInterface)
>>> referenced by data.o:(LibStubUnicodeInterface)
clang: error: linker command failed with exit code 1 (use -v to see invocation)
make: *** [Makefile:8: all] Error 1

I hope ill get help with problem

Upvotes: 0

Views: 20

Answers (0)

Related Questions