Page 1 of 1

g++ Problem with Pointer Size

Posted: Tue Sep 15, 2015 8:50 am
by sebihepp
Hi guys,

I have a problem with my kernel code. I switched from c to c++ and get the compile error: conversion to uin32_t from Struct* looses precision
I found out, that this should be related to gcc using 64bit pointers. But hey, I am programming a 32bit one. I tried -32 but that leads to an error, that the linker cannot read the object files. Then I tried -march=486 and this leads to another error: This architecture doesn't support X86_64
This doesn't happen with gcc and c as language. I don't know, what I should do now... I have a totally black out.

Best regards
Sebi

Re: g++ Problem with Pointer Size

Posted: Tue Sep 15, 2015 9:33 am
by madanra
Are you using a cross compiler?

Re: g++ Problem with Pointer Size

Posted: Tue Sep 15, 2015 9:35 am
by xenos

Re: g++ Problem with Pointer Size

Posted: Tue Sep 15, 2015 9:42 am
by sebihepp
I just figured it our too. All my cpp files are processed using the normal compiler (g++) But why? In my makefile I explicitely call i686-elf-g++. Are those + signs the problem?

Content of my makefile:

Code: Select all

AS = i686-elf-as
CC = i686-elf-gcc
CPP = i686-elf-g++

CFLAGS = -c -ffreestanding -nostdlib -O2 -Wall -Wextra -std=gnu99 -I../../include
CPPFLAGS = -c -ffreestanding -nostdlib -O2 -Wall -Wextra -fno-exceptions -fno-rtti -I../../include
LFLAGS = -T linker.ld -ffreestanding -O2 -nostdlib -lgcc


OUTPUT = heidelberg.bin
KERNEL_OBJECTS = boot.o main.o multiboot.o paging.o
OBJECTS = $(KERNEL_OBJECTS)


.PHONY: all
.PHONY: clean

all: $(OUTPUT)

$(OUTPUT): $(OBJECTS)
	$(CC) $(LFLAGS) -o $@ $(OBJECTS)

%.o: %.s
	$(AS) -o $@ $<

%.o: %.c
	$(CC) $(CFLAGS) -o $@ $<

%o: %.cpp
	$(CPP) $(CPPFLAGS) -o $@ $<
	
clean:
	rm *.o $(OUTPUT)
	

Re: g++ Problem with Pointer Size

Posted: Tue Sep 15, 2015 10:12 am
by madanra
I don't know if this is related to your problem, but I noticed you're linking with $(CC):

Code: Select all

$(OUTPUT): $(OBJECTS)
   $(CC) $(LFLAGS) -o $@ $(OBJECTS)
Should this be $(CPP), given some of the object files are C++?

Re: g++ Problem with Pointer Size

Posted: Tue Sep 15, 2015 10:23 am
by Roman

Code: Select all

%o: %.cpp

Re: g++ Problem with Pointer Size

Posted: Tue Sep 15, 2015 10:41 am
by sebihepp
Roman wrote:

Code: Select all

%o: %.cpp
Yeah, that was the problem. Thank you very much. I think I would have been spent another few weeks, until I had seen this. :-D
madanra wrote:I don't know if this is related to your problem, but I noticed you're linking with $(CC):

Code: Select all

$(OUTPUT): $(OBJECTS)
   $(CC) $(LFLAGS) -o $@ $(OBJECTS)
Should this be $(CPP), given some of the object files are C++?
This step is only the linking, so compiling is already done. That's why I use normal gcc. I've read in the wiki, that you shouldn't use ld, but gcc, because gcc is doing some more things that could be required.

Re: g++ Problem with Pointer Size

Posted: Wed Sep 16, 2015 3:54 am
by xenos
Further, it should not be CPP / CPPFLAGS - that would be the preprocessor. Use CXX / CXXFLAGS for the C++ compiler.

Re: g++ Problem with Pointer Size

Posted: Wed Sep 16, 2015 6:22 am
by Roman
You also shouldn't define rules for *.c and *.cpp files. Just set CC, CXX, CFLAGS, CXXFLAGS (C++ compiler flags) and CPPFLAGS (preprocessor flags, both C and C++).

Re: g++ Problem with Pointer Size

Posted: Wed Sep 16, 2015 7:40 am
by sebihepp
Roman wrote:You also shouldn't define rules for *.c and *.cpp files. Just set CC, CXX, CFLAGS, CXXFLAGS (C++ compiler flags) and CPPFLAGS (preprocessor flags, both C and C++).
Well, how do I know then, when to call CC and when CXX? :?:

Edit: Okay, I just found a website about predefined implicit rules in make. So I don't need them, just define CC, CXX, etc. and use rules to link, clean, and so on...
XenOS wrote:Further, it should not be CPP / CPPFLAGS - that would be the preprocessor. Use CXX / CXXFLAGS for the C++ compiler.
Thanks, One more thing I have learned. :)