I am writing my very first program to uefi usig tutorial: http://www.rodsbooks.com/efi-programming/hello.html and I have problem to compile it.
Here is my makefile:
ARCH = $(shell uname -m |sed s,i[3456789]86,ia32,)
OBJ = helloUEFI.o
TARGET = helloUEFI.efi
EFIINC = /usr/include/efi
EFIINCS = -I$(EFIINC) -I$(EFIINC)/$(ARCH) -I$(EFIINC)/protocol
LIB = /usr/lib
EFILIB = /usr/lib
EFI_CRT_OBJS = $(EFILIB)/crt0-efi-$(ARCH).o
EFI_LDS = $(EFILIB)/elf_$(ARCH)_efi.lds
CFALGS = $(EFIINCS) -fno-stack-protector -fPIC -fshort-wchar -fmno-red-zone -Wall
ifeq ($(ARCH),x86_64)
CFLAGS += -DEFI_FUNCTION_WRAPPER
endif
LDFLAGS = -nonstdlib -znocombreloc -T $(EFI_LDS) -shared -Bsymbolic -L $(EFILIB) -L $(LIB) $(EFI_CRT_OBJS)
all: $(TARGET)
helloUEFI.so: $(OBJS)
ld $(LDFLAGS) $(OBJS) -o $@ -lefi -lgnuefi
%.efi: %.so
objcopy -j .text -j .sdata -j .data -j .dynamic -j .dynsym -j .rel -j .rela -j.reloc --target=efi-app-$(ARCH) $^ $@
and my hello world program:
#include <efi.h>
#include <efilib.h>
EFI_STATUS
EFIAPI
efi_main (EFI_HANDLE ImageHandle, EFI_SYSTEM_TABLE* SydstemTable) {
InitializeLib(ImageHandle, SystemTable);
Print(L"Hello UEFI!\n");
return EFI_SUCCESS;
}
error message:
ld -nonstdlib -znocombreloc -T /usr/lib/elf_x86_64_efi.lds -shared -Bsymbolic -L /usr/lib -L /usr/lib /usr/lib/crt0-efi-x86_64.o -o helloUEFI.so -lefi -lgnuefi
ld: /usr/lib/crt0-efi-x86_64.o: relocation R_X86_64_PC32 against undefined symbol `efi_main' can not be used when making a shared object; recompile with -fPIC
ld: final link failed
I'd check path to lib and includes, and I add -fPIC to my compile flags and nothing helps.
I would be grateful for some advise what to do
My system info:
Ubuntu 15.10 64-bits
CFALGS should be spelled CFLAGS. This one gets me all the time.
Hopefully that helps. I would have posted this in a comment but I don't have the rep.