I am currently working on a bootloader with some friends but I cannot figure this out. These are the structs.
typedef struct {
void* BaseAddress; // a void pointer holds the address of any type of variable
size_t BufferSize; // controls how big the buffer is (a buffer is a little place of data)
unsigned int Width, Height;
// screen height and width
unsigned int PixelsPerScanLine; // Pixels per scan line is how you determinine your refresh rate
} Framebuffer; // the name of the class and what this class does is outputs the pixels
typedef struct {
unsigned char magic[2]; // we call it magic because this is the bytes the header stores that lets us identify that the psf file is a psf file
unsigned char mode; // the mode that the psf font is in
unsigned char charsize; // defines how large the characters are in bytes
} FONT_HEADER;
typedef struct {
FONT_HEADER* fontHdr;
void* glyphBuffer; // keeps data about the piece of text or character
} FONT;
These are the structs that have errors, the errors below state that there was a previous declaration of the struct or type but it is in the same place as where the error is.
In file included from src_uefi/main_uefi.c:9:
src_uefi/include/fb.h:15:3: error: conflicting types for ‘Framebuffer’
15 | } Framebuffer; // the name of the class and what this class does is outputs the pixels
| ^~~~~~~~~~~
In file included from src_uefi/include/gop.h:2,
from src_uefi/main_uefi.c:4:
src_uefi/include/fb.h:15:3: note: previous declaration of ‘Framebuffer’ was here
15 | } Framebuffer; // the name of the class and what this class does is outputs the pixels
| ^~~~~~~~~~~
In file included from src_uefi/main_uefi.c:9:
src_uefi/include/fb.h:17:20: error: conflicting types for ‘fb’
17 | extern Framebuffer fb;
| ^~
In file included from src_uefi/include/gop.h:2,
from src_uefi/main_uefi.c:4:
src_uefi/include/fb.h:17:20: note: previous declaration of ‘fb’ was here
17 | extern Framebuffer fb;
| ^~
In file included from src_uefi/main_uefi.c:9:
src_uefi/include/fb.h:26:3: error: conflicting types for ‘FONT_HEADER’
26 | } FONT_HEADER;
| ^~~~~~~~~~~
In file included from src_uefi/include/gop.h:2,
from src_uefi/main_uefi.c:4:
src_uefi/include/fb.h:26:3: note: previous declaration of ‘FONT_HEADER’ was here
26 | } FONT_HEADER;
| ^~~~~~~~~~~
In file included from src_uefi/main_uefi.c:9:
src_uefi/include/fb.h:31:3: error: conflicting types for ‘FONT’
31 | } FONT;
| ^~~~
In file included from src_uefi/include/gop.h:2,
from src_uefi/main_uefi.c:4:
src_uefi/include/fb.h:31:3: note: previous declaration of ‘FONT’ was here
31 | } FONT;
| ^~~~
In file included from src_uefi/main_uefi.c:9:
src_uefi/include/fb.h:34:7: error: conflicting types for ‘LoadFont’
34 | FONT* LoadFont(EFI_FILE_PROTOCOL* Directory, CHAR16* Path, EFI_HANDLE ImageHandle, EFI_SYSTEM_TABLE* SystemTable);
| ^~~~~~~~
In file included from src_uefi/include/gop.h:2,
from src_uefi/main_uefi.c:4:
src_uefi/include/fb.h:34:7: note: previous declaration of ‘LoadFont’ was here
34 | FONT* LoadFont(EFI_FILE_PROTOCOL* Directory, CHAR16* Path, EFI_HANDLE ImageHandle, EFI_SYSTEM_TABLE* SystemTable);
| ^~~~~~~~
src_uefi/main_uefi.c: In function ‘main_uefi’:
src_uefi/main_uefi.c:141:83: error: initialization of ‘int (__attribute__((sysv_abi)) *)(Framebuffer *, FONT, BootInfo *)’ from incompatible pointer type ‘int (__attribute__((sysv_abi)) *)(BootInfo *)’ [-Werror=incompatible-pointer-types]
141 | __attribute__((sysv_abi)) int (*KernelEntry)(Framebuffer*, FONT, BootInfo*) = ((__attribute__((sysv_abi)) int (*)(BootInfo*) ) kernel_elf_header->e_entry);
| ^
src_uefi/main_uefi.c:159:33: error: initialization of ‘Framebuffer *’ {aka ‘struct <anonymous> *’} from incompatible pointer type ‘Framebuffer *’ {aka ‘struct <anonymous> *’} [-Werror=incompatible-pointer-types]
159 | Framebuffer* kernelBuffer = initGOP();
| ^~~~~~~
src_uefi/main_uefi.c:161:17: error: statement with no effect [-Werror=unused-value]
161 | kernelBuffer->BaseAddress;
| ~~~~~~~~~~~~^~~~~~~~~~~~~
src_uefi/main_uefi.c:162:17: error: statement with no effect [-Werror=unused-value]
162 | kernelBuffer->BufferSize;
| ~~~~~~~~~~~~^~~~~~~~~~~~
src_uefi/main_uefi.c:163:17: error: statement with no effect [-Werror=unused-value]
163 | kernelBuffer->Width;
| ~~~~~~~~~~~~^~~~~~~
src_uefi/main_uefi.c:164:17: error: statement with no effect [-Werror=unused-value]
164 | kernelBuffer->Height;
| ~~~~~~~~~~~~^~~~~~~~
src_uefi/main_uefi.c:165:17: error: statement with no effect [-Werror=unused-value]
165 | kernelBuffer->PixelsPerScanLine;
| ~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~
src_uefi/main_uefi.c:167:31: error: incompatible type for argument 2 of ‘KernelEntry’
167 | KernelEntry(kernelBuffer, kernelFont, bootinfo);
| ^~~~~~~~~~
| |
| FONT * {aka struct <anonymous> *}
src_uefi/main_uefi.c:167:31: note: expected ‘FONT’ {aka ‘struct <anonymous>’} but argument is of type ‘FONT *’ {aka ‘struct <anonymous> *’}
cc1: all warnings being treated as errors
What am I doing wrong and what do I need to change?
CodePudding user response:
Add code guards to fb.h
to allow it to be included multiple times.
CodePudding user response:
In researching this issue, I found this similar issue out on the web that seems to relate to the same problem Conflicting type.
I tested out some scenarios and it most likely looks like within your "gop.h" header file, there is a statement to include the "fb.h" header file.
#include fb.h
Then within your "main.c" program you most likely have include statements for both "fb.h" and "gop.h" files as in the following code snippet.
#include "fb.h"
#include "gop.h"
So, the structure definitions are getting referenced a second time.
That is the most likely cause. If that is indeed the case, you probably will want to look at the proposed solution within the link I referenced.
Hope that helps.
Regards.