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.
cklie97
Posts: 18 Joined: Tue Apr 19, 2016 2:11 am
Post
by cklie97 » Sun Jul 03, 2016 3:49 am
Hello there. While writing my kernel I'm now at a point where I want to use both c, because most of my code is written in it and c++, because of classes.
At the moment I use "make" to help me compiling, but I don'nt get it why the Makefile I wrote for c and c++ do not work.
Makefile
Code: Select all
SRCS = $(shell find ./code -name '*.[cppS]')
OBJS = $(addsuffix .o,$(basename $(SRCS)))
CC = gcc
CPP = g++
LD = ld
ASFLAGS = -m32
CFLAGS = -m32 -Wall -g -fno-stack-protector -nostdinc
CPPFLAGS = -m32 -Wall -g -fno-stack-protector -nostdinc
LDFLAGS = -melf_i386 -Tcode/kernel.ld
kernel: $(OBJS)
$(LD) $(LDFLAGS) -o $@ $^
%.o: %.c
$(CC) $(CFLAGS) -c -o $@ $^
%.o: %.cpp
$(CPP) $(CPPFLAGS) -c -o $@ $^
%.o: %.S
$(CC) $(ASFLAGS) -c -o $@ $^
clean:
rm $(OBJS)
.PHONY: clean
The problem:
My *.cpp files are not compiled (missing *.o files)
iansjack
Member
Posts: 4706 Joined: Sat Mar 31, 2012 3:07 am
Location: Chichester, UK
Post
by iansjack » Sun Jul 03, 2016 3:57 am
Output from the make command?
cklie97
Posts: 18 Joined: Tue Apr 19, 2016 2:11 am
Post
by cklie97 » Sun Jul 03, 2016 4:05 am
Make output:
gcc -m32 -Wall -g -fno-stack-protector -nostdinc -c -o code/string.o code/string.c
gcc -m32 -c -o code/int_stub.o code/int_stub.S
gcc -m32 -Wall -g -fno-stack-protector -nostdinc -c -o code/keyboard.o code/keyboard.c
gcc -m32 -Wall -g -fno-stack-protector -nostdinc -c -o code/interrupt_descriptor_table.o code/interrupt_descriptor_table.c
gcc -m32 -Wall -g -fno-stack-protector -nostdinc -c -o code/memory_manager.o code/memory_manager.c
gcc -m32 -Wall -g -fno-stack-protector -nostdinc -c -o code/global_descriptor_table.o code/global_descriptor_table.c
gcc -m32 -Wall -g -fno-stack-protector -nostdinc -c -o code/assembler.o code/assembler.c
gcc -m32 -Wall -g -fno-stack-protector -nostdinc -c -o code/main.o code/main.c
gcc -m32 -Wall -g -fno-stack-protector -nostdinc -c -o code/console.o code/console.c
gcc -m32 -c -o code/start.o code/start.S
gcc -m32 -Wall -g -fno-stack-protector -nostdinc -c -o code/shell.o code/shell.c
ld -melf_i386 -Tcode/kernel.ld -o kernel code/string.o code/int_stub.o code/keyboard.o code/interrupt_descriptor_table.o code/memory_manager.o code/global_descriptor_table.o code/assembler.o code/main.o code/console.o code/start.o code/shell.o
gerryg400
Member
Posts: 1801 Joined: Thu Mar 25, 2010 11:26 pm
Location: Melbourne, Australia
Post
by gerryg400 » Sun Jul 03, 2016 4:07 am
I think this is wrong. This means *.c or *.p or *.S. It doesn't match with cpp at all.
If a trainstation is where trains stop, what is a workstation ?
cklie97
Posts: 18 Joined: Tue Apr 19, 2016 2:11 am
Post
by cklie97 » Sun Jul 03, 2016 4:25 am
Thanks that helped. Now the *.cpp files are getting compiled.
new Makefile
SRCS = $(shell find ./code -name '*.[cS]' -or -name '*.cpp')
[...]
But now I have a problem with the linker.
Output
Code: Select all
ld -melf_i386 -Tcode/kernel.ld -o kernel code/string.o code/int_stub.o code/keyboard.o code/interrupt_descriptor_table.o code/memory_manager.o code/global_descriptor_table.o code/assembler.o code/main.o code/console.o code/start.o code/shell.o code/t32.o
code/main.o: In Funktion `main':
code/main.c:13: Nicht definierter Verweis auf `test'
main.c
Code: Select all
[...]
#include "t32.h"
10 int main(void)
11 {
12 init();
13 test();
14 while(1);
15 return 0;
16 }
[...]
t32.h
t32.cpp
heat
Member
Posts: 103 Joined: Sat Mar 28, 2015 11:23 am
Libera.chat IRC: heat
Post
by heat » Sun Jul 03, 2016 5:12 am
cklie97 wrote: Thanks that helped. Now the *.cpp files are getting compiled.
new Makefile
SRCS = $(shell find ./code -name '*.[cS]' -or -name '*.cpp')
[...]
But now I have a problem with the linker.
Output
Code: Select all
ld -melf_i386 -Tcode/kernel.ld -o kernel code/string.o code/int_stub.o code/keyboard.o code/interrupt_descriptor_table.o code/memory_manager.o code/global_descriptor_table.o code/assembler.o code/main.o code/console.o code/start.o code/shell.o code/t32.o
code/main.o: In Funktion `main':
code/main.c:13: Nicht definierter Verweis auf `test'
main.c
Code: Select all
[...]
#include "t32.h"
10 int main(void)
11 {
12 init();
13 test();
14 while(1);
15 return 0;
16 }
[...]
t32.h
t32.cpp
I'm not sure if you know what C++ name decoration/mangling is... i suggest you learn more about the linking process.
If some of you people keep insisting on having backwards compatibitity with the stone age, we'll have stone tools forever.
My Hobby OS:
https://github.com/heatd/Onyx
Roman
Member
Posts: 568 Joined: Thu Mar 27, 2014 3:57 am
Location: Moscow, Russia
Contact:
Post
by Roman » Sun Jul 03, 2016 6:42 am
Don't forget C++ names are mangled to contain type information. If you want a C++ function to be callable from C, you need to declare it with extern "C" .
"If you don't fail at least 90 percent of the time, you're not aiming high enough."
- Alan Kay