The problem is that when I go to compile, it says:
Code: Select all
kernel.cpp:(.text+0x52): undefined reference to `std::basic_ifstream<char, std::char_traits<char> >::basic_ifstream()'
ld: kernel.cpp:(.text+0x6d): undefined reference to `std::basic_ifstream<char, std::char_traits<char> >::open(char const*, std::_Ios_Openmode)'
make: *** [Makefile:47: link] Error 1
Does anyone know how to fix this?
PS: I am following off of this tutorial: https://github.com/Absurdponcho/PonchoO ... ead/kernel
Here is the code:
Makefile:
Code: Select all
OSNAME = CustomOS
GNUEFI = ../gnu-efi
OVMFDIR = ../OVMFbin
LDS = kernel.ld
CC = g++
ASMC = nasm
LD = ld
CFLAGS = -ffreestanding -fshort-wchar -mno-red-zone -fno-exceptions
ASMFLAGS =
LDFLAGS = -T $(LDS) -static -Bsymbolic -nostdlib
SRCDIR := src
OBJDIR := lib
BUILDDIR = bin
BOOTEFI := $(GNUEFI)/x86_64/bootloader/main.efi
rwildcard=$(foreach d,$(wildcard $(1:=/*)),$(call rwildcard,$d,$2) $(filter $(subst *,%,$2),$d))
SRC = $(call rwildcard,$(SRCDIR),*.cpp)
ASMSRC = $(call rwildcard,$(SRCDIR),*.asm)
OBJS = $(patsubst $(SRCDIR)/%.cpp, $(OBJDIR)/%.o, $(SRC))
OBJS += $(patsubst $(SRCDIR)/%.asm, $(OBJDIR)/%_asm.o, $(ASMSRC))
DIRS = $(wildcard $(SRCDIR)/*)
kernel: $(OBJS) link
$(OBJDIR)/interrupts/interrupts.o: $(SRCDIR)/interrupts/interrupts.cpp
@ echo !==== COMPILING $^
@ mkdir -p $(@D)
$(CC) -mno-red-zone -mgeneral-regs-only -ffreestanding -c $^ -o $@
$(OBJDIR)/%.o: $(SRCDIR)/%.cpp
@ echo !==== COMPILING $^
@ mkdir -p $(@D)
$(CC) $(CFLAGS) -c $^ -o $@
$(OBJDIR)/%_asm.o: $(SRCDIR)/%.asm
@ echo !==== COMPILING $^
@ mkdir -p $(@D)
$(ASMC) $(ASMFLAGS) $^ -f elf64 -o $@
link:
@ echo !==== LINKING
$(LD) $(LDFLAGS) -o $(BUILDDIR)/kernel.elf $(OBJS)
setup:
@mkdir $(BUILDDIR)
@mkdir $(SRCDIR)
@mkdir $(OBJDIR)
buildimg:
dd if=/dev/zero of=$(BUILDDIR)/$(OSNAME).img bs=512 count=93750
mformat -i $(BUILDDIR)/$(OSNAME).img -f 1440 ::
mmd -i $(BUILDDIR)/$(OSNAME).img ::/EFI
mmd -i $(BUILDDIR)/$(OSNAME).img ::/EFI/BOOT
mcopy -i $(BUILDDIR)/$(OSNAME).img $(BOOTEFI) ::/EFI/BOOT
mcopy -i $(BUILDDIR)/$(OSNAME).img startup.nsh ::
mcopy -i $(BUILDDIR)/$(OSNAME).img $(BUILDDIR)/kernel.elf ::
mcopy -i $(BUILDDIR)/$(OSNAME).img $(BUILDDIR)/zap-light16.psf ::
run:
qemu-system-x86_64 -drive file=$(BUILDDIR)/$(OSNAME).img -m 256M -cpu qemu64 -drive if=pflash,format=raw,unit=0,file="$(OVMFDIR)/OVMF_CODE-pure-efi.fd",readonly=on -drive if=pflash,format=raw,unit=1,file="$(OVMFDIR)/OVMF_VARS-pure-efi.fd" -net none
kernel.cpp
Code: Select all
#include <fstream>
#include <stdint.h>
using namespace std;
#include "kernelUtil.h"
#include "eif.h"
#include "userinput/keyboard.h"
#include "prepare_os/prepare-os.h"
#include "prepare_os/frame_handler.h"
#include "ahci/ahci.h"
extern "C" void _start(BootInfo* bootInfo){
KernelInfo kernelInfo = InitializeKernel(bootInfo);
GlobalRenderer->Clear();
IntInfo defaultInfo = GetDefaultIntfSettings();
// this is just to make the interface (basically just plotting pixels)
InitializeInterface(defaultInfo);
// Here is where I do the file opening
ifstream myFile;
// I am just testing this out to see if it compiles,
myFile.open("info/username.txt");
while(true){
asm ("hlt");
}
}