g++ Problem with Pointer Size
-
sebihepp
- Member

- Posts: 256
- Joined: Tue Aug 26, 2008 11:24 am
- GitHub: https://github.com/sebihepp
g++ Problem with Pointer Size
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
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
Are you using a cross compiler?
- xenos
- Member

- Posts: 1143
- Joined: Thu Aug 11, 2005 11:00 pm
- Libera.chat IRC: xenos1984
- Location: Tartu, Estonia
- GitHub: https://github.com/xenos1984
- Contact:
-
sebihepp
- Member

- Posts: 256
- Joined: Tue Aug 26, 2008 11:24 am
- GitHub: https://github.com/sebihepp
Re: g++ Problem with Pointer Size
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:
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
I don't know if this is related to your problem, but I noticed you're linking with $(CC):
Should this be $(CPP), given some of the object files are C++?
Code: Select all
$(OUTPUT): $(OBJECTS)
$(CC) $(LFLAGS) -o $@ $(OBJECTS)Re: g++ Problem with Pointer Size
Code: Select all
%o: %.cpp
"If you don't fail at least 90 percent of the time, you're not aiming high enough."
- Alan Kay
- Alan Kay
-
sebihepp
- Member

- Posts: 256
- Joined: Tue Aug 26, 2008 11:24 am
- GitHub: https://github.com/sebihepp
Re: g++ Problem with Pointer Size
Yeah, that was the problem. Thank you very much. I think I would have been spent another few weeks, until I had seen this.Roman wrote:Code: Select all
%o: %.cpp
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.madanra wrote:I don't know if this is related to your problem, but I noticed you're linking with $(CC):
Should this be $(CPP), given some of the object files are C++?Code: Select all
$(OUTPUT): $(OBJECTS) $(CC) $(LFLAGS) -o $@ $(OBJECTS)
- xenos
- Member

- Posts: 1143
- Joined: Thu Aug 11, 2005 11:00 pm
- Libera.chat IRC: xenos1984
- Location: Tartu, Estonia
- GitHub: https://github.com/xenos1984
- Contact:
Re: g++ Problem with Pointer Size
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
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++).
"If you don't fail at least 90 percent of the time, you're not aiming high enough."
- Alan Kay
- Alan Kay
-
sebihepp
- Member

- Posts: 256
- Joined: Tue Aug 26, 2008 11:24 am
- GitHub: https://github.com/sebihepp
Re: g++ Problem with Pointer Size
Well, how do I know then, when to call CC and when CXX?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++).
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...
Thanks, One more thing I have learned.XenOS wrote:Further, it should not be CPP / CPPFLAGS - that would be the preprocessor. Use CXX / CXXFLAGS for the C++ compiler.
