fatal error: stddef.h: No such file or directory

Question about which tools to use, bugs, the best way to implement a function, etc should go here. Don't forget to see if your question is answered in the wiki first! When in doubt post here.
Post Reply
jamesread
Member
Member
Posts: 49
Joined: Wed Dec 09, 2020 11:32 am

fatal error: stddef.h: No such file or directory

Post 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:1210: 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:12629: 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
Octocontrabass
Member
Member
Posts: 5568
Joined: Mon Mar 25, 2013 7:01 pm

Re: fatal error: stddef.h: No such file or directory

Post by Octocontrabass »

Why are you building GCC instead of using Ubuntu's prebuilt Mingw-w64 package or Clang?
User avatar
Solar
Member
Member
Posts: 7615
Joined: Thu Nov 16, 2006 12:01 pm
Location: Germany
Contact:

Re: fatal error: stddef.h: No such file or directory

Post by Solar »

...because our Wiki page says so?
Every good solution is obvious once you've found it.
jamesread
Member
Member
Posts: 49
Joined: Wed Dec 09, 2020 11:32 am

Re: fatal error: stddef.h: No such file or directory

Post 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?
nexos
Member
Member
Posts: 1081
Joined: Tue Feb 18, 2020 3:29 pm
Libera.chat IRC: nexos

Re: fatal error: stddef.h: No such file or directory

Post by nexos »

For mingw, it is either x86_64-w64-mingw32-gcc or i686-w64-mingw32-gcc
"How did you do this?"
"It's very simple — you read the protocol and write the code." - Bill Joy
Projects: NexNix | libnex | nnpkg
jamesread
Member
Member
Posts: 49
Joined: Wed Dec 09, 2020 11:32 am

Re: fatal error: stddef.h: No such file or directory

Post 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.
nexos
Member
Member
Posts: 1081
Joined: Tue Feb 18, 2020 3:29 pm
Libera.chat IRC: nexos

Re: fatal error: stddef.h: No such file or directory

Post 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.
"How did you do this?"
"It's very simple — you read the protocol and write the code." - Bill Joy
Projects: NexNix | libnex | nnpkg
User avatar
bzt
Member
Member
Posts: 1584
Joined: Thu Oct 13, 2016 4:55 pm
Contact:

Re: fatal error: stddef.h: No such file or directory

Post 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
jamesread
Member
Member
Posts: 49
Joined: Wed Dec 09, 2020 11:32 am

Re: fatal error: stddef.h: No such file or directory

Post 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
User avatar
bzt
Member
Member
Posts: 1584
Joined: Thu Oct 13, 2016 4:55 pm
Contact:

Re: fatal error: stddef.h: No such file or directory

Post 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
Octocontrabass
Member
Member
Posts: 5568
Joined: Mon Mar 25, 2013 7:01 pm

Re: fatal error: stddef.h: No such file or directory

Post 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().
Post Reply