kernel.cpp在制作kernel.o时显示错误和Makefile错误

时间:2017-07-29 17:56:34

标签: c++ linux makefile operating-system kernel

错误是:(我理解警告,请纠正错误)

root@kali:~/Desktop/Ohm Os# make kernel.o

g++ -m32 -o kernel.o -c kernel.cpp

kernel.cpp: In function ‘void kernelMain(void*, unsigned int)’:

kernel.cpp:27:25: warning: ISO C++ forbids converting a string constant to 

‘char*’ [-Wwrite-strings]

     printf("HELLO WORLD");
                         ^
kernel.cpp:31:1: error: expected primary-expression before ‘}’ token
 }
 ^

Makefile:9: recipe for target 'kernel.o' failed

make: *** [kernel.o] Error 1

这是我的KERNEL.CPP:

void printf(char* str)
{
    unsigned short* VideoMemory = (unsigned short*)0xb8000;
    for(int i = 0; str[i] != '\0'; ++i)
        VideoMemory[i] = (VideoMemory[i] & 0xFF00) | str[i];
}

void kernelMain(void* multiboot_structure, unsigned int magicnumber)
{
    printf("HELLO WORLD");
    while(1)
}

还有我的Makefile:

GPPPARAMS = -m32
ASPARAMS = --32
LDPARAMS = -melf_i386
ojects = loader.o kernel.o

%.o: %.cpp
    g++ $(GPPPARAMS) -o $@ -c $<

%.o: %.s
    as $(ASPARAMS) -o $@ $<

mykernel.bin: linker.ld $(objects)
    ld $(LDPARAMS) -T $< -o $@ $(objects)

install: mykernel.bin
    sudo cp $< /boot/mykernel.bin

2 个答案:

答案 0 :(得分:2)

kernel.cpp:31:1:错误:在'}'标记之前预期的primary-expression  }

尝试: 而(1);

答案 1 :(得分:0)

您确定您了解警告的后果吗?

至于错误,您似乎混合了do whilewhile的语法

您需要使用

while (condition)
  statement

do
  statement
while (condition)