Page 1 of 1
fatal error: stddef.h: No such file or directory
Posted: Wed Dec 09, 2020 11:50 pm
by jamesread
Hi,
I'm working through the UEFI App Bare Bones tutorial
https://wiki.osdev.org/UEFI_Bare_Bones
I'm at the first step. Developers will need a GCC Cross-Compiler targeting the x86_64-w64-mingw32
I managed to run make all-gcc without any errors but when running make all-target-libgcc I get the following error:
- /home/yaakov/osdev/build-gcc-x86_64-w64-mingw32/gcc/include/stddef.h:1:15: fatal error: stddef.h: No such file or directory
1 | #include_next <stddef.h>
| ^~~~~~~~~~
compilation terminated.
make[3]: *** [Makefile:498: _muldi3.o] Error 1
make[3]: Leaving directory '/home/yaakov/osdev/build-gcc-x86_64-w64-mingw32/x86_64-w64-mingw32/32/libgcc'
make[2]: *** [Makefile multi-do] Error 1
Is this something to do with the versions I am using?
make[2]: Leaving directory '/home/yaakov/osdev/build-gcc-x86_64-w64-mingw32/x86_64-w64-mingw32/libgcc'
make[1]: *** [Makefile:127: all-multi] Error 2
make[1]: Leaving directory '/home/yaakov/osdev/build-gcc-x86_64-w64-mingw32/x86_64-w64-mingw32/libgcc'
make: *** [Makefile all-target-libgcc] Error 2
I am compiling gcc-9.3.0
My compiler version is gcc (Ubuntu 9.3.0-17ubuntu1~20.04) 9.3.0
Re: fatal error: stddef.h: No such file or directory
Posted: Thu Dec 10, 2020 3:30 am
by Octocontrabass
Why are you building GCC instead of using Ubuntu's prebuilt Mingw-w64 package or Clang?
Re: fatal error: stddef.h: No such file or directory
Posted: Thu Dec 10, 2020 4:14 am
by Solar
...because our Wiki page says so?
Re: fatal error: stddef.h: No such file or directory
Posted: Thu Dec 10, 2020 6:11 am
by jamesread
Octocontrabass wrote:Why are you building GCC instead of using Ubuntu's prebuilt Mingw-w64 package or Clang?
I've installed both packages as you suggested. How do I now invoke the use of the new gcc version and ld also?
Re: fatal error: stddef.h: No such file or directory
Posted: Thu Dec 10, 2020 7:01 am
by nexos
For mingw, it is either x86_64-w64-mingw32-gcc or i686-w64-mingw32-gcc
Re: fatal error: stddef.h: No such file or directory
Posted: Thu Dec 10, 2020 7:19 am
by jamesread
nexos wrote:For mingw, it is either x86_64-w64-mingw32-gcc or i686-w64-mingw32-gcc
OK. Both of those are invocable from my CLI. Just as a side thought. Why do we need a mingw cross compiler? We are not compiling for windows.
Re: fatal error: stddef.h: No such file or directory
Posted: Thu Dec 10, 2020 7:53 am
by nexos
EFI apps are Windows apps with a different subsystem. EFI firmware was very much influenced by MS, hence it uses the same ABI, executable format, function naming style, and so on as MS stuff.
Re: fatal error: stddef.h: No such file or directory
Posted: Thu Dec 10, 2020 9:19 am
by bzt
Using a cross-compiler with GNU-EFI is generally a bad idea. The complexity demonstrated on that UEFI Bare Bones page showcases that well (uses some source files directly instead of a library for example).
I've added an explanation and linked
https://wiki.osdev.org/GNU-EFI page which describes the preferred way how GNU-EFI should be used. On the other hand I've also linked the UEFI Bare Bones page on the GNU-EFI page for those who insist to use a cross-compiler.
Cheers,
bzt
Re: fatal error: stddef.h: No such file or directory
Posted: Thu Dec 10, 2020 12:10 pm
by jamesread
bzt wrote:Using a cross-compiler with GNU-EFI is generally a bad idea. The complexity demonstrated on that UEFI Bare Bones page showcases that well (uses some source files directly instead of a library for example).
I've added an explanation and linked
https://wiki.osdev.org/GNU-EFI page which describes the preferred way how GNU-EFI should be used. On the other hand I've also linked the UEFI Bare Bones page on the GNU-EFI page for those who insist to use a cross-compiler.
Cheers,
bzt
I have successfully (I think) followed the steps up to
Code: Select all
objcopy -j .text -j .sdata -j .data -j .dynamic -j .dynsym -j .rel -j .rela -j .rel.* -j .rela.* -j .reloc --target efi-app-x86_64 --subsystem=10 main.so main.efi
Then I am bit confused as to what to do next. The tutorial says
Now you can copy main.efi to your EFI System Partition, and after boot run it from the EFI Shell. Or you can rename it to EFI\BOOT\BOOTX64.EFI and it should be executed automatically on boot.
I'm not sure what this means. Should I continue with the UEFI App Bare Bones from
Creating the FAT image
Next, create a FAT filesystem image.
dd if=/dev/zero of=fat.img bs=1k count=1440
mformat -i fat.img -f 1440 ::
mmd -i fat.img ::/EFI
mmd -i fat.img ::/EFI/BOOT
mcopy -i fat.img BOOTX64.EFI ::/EFI/BOOT
Re: fatal error: stddef.h: No such file or directory
Posted: Thu Dec 10, 2020 1:46 pm
by bzt
jamesread wrote:Then I am bit confused as to what to do next. The tutorial says
Now you can copy main.efi to your EFI System Partition, and after boot run it from the EFI Shell. Or you can rename it to EFI\BOOT\BOOTX64.EFI and it should be executed automatically on boot.
I'm not sure what this means. Should I continue with the UEFI App Bare Bones from Creating the FAT image
This only means you have to copy your compiled file (main.efi) to the ESP partition (as EFI/BOOT/BOOTX64.EFI) so that the UEFI firmware could find it in boot-time. You can follow that tutorial, follow the steps on wiki UEFI page, follow the Bootable Disk tutorial, or use an existing image and replace that one file as I wrote
here. The point is, you have to copy your loader to the ESP somehow, but it doesn't matter how you do it.
Cheers,
bzt
Re: fatal error: stddef.h: No such file or directory
Posted: Thu Dec 10, 2020 2:06 pm
by Octocontrabass
bzt wrote:Using a cross-compiler with GNU-EFI is generally a bad idea.
The example on the wiki only uses GNU-EFI for its UEFI headers and doesn't link against it or use its build system. It won't work correctly if you follow the typical GNU-EFI build process anyway, since it doesn't use InitializeLib() or uefi_call_wrapper().