【发布时间】:2018-01-05 15:16:23
【问题描述】:
错误是:(我理解警告,请纠正错误)
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
【问题讨论】:
-
为什么要用
make变量和后缀规则重新发明轮子?默认情况下有一些非常好的,可以很容易地适应大多数用途。它们还具有被普遍理解的优势,这有助于您的 makefile 的可维护性。 -
在结尾处缺少一些东西:
while(1)。错字? -
是的,你可能会在警告中幸存下来。但是为什么
printf期待char*?在抱怨const char *到char *转换的编译器中看到这种情况很奇怪。您是否尝试将旧标准库与现代编译器一起使用? -
我正在开发一个我 18 岁的操作系统,感谢大家的帮助
-
我不建议使用您不太熟悉的语言编写操作系统内核。也请看OSDEV
标签: c++ linux makefile operating-system kernel