gbadev.org forum archive

This is a read-only mirror of the content originally found on forum.gbadev.org (now offline), salvaged from Wayback machine copies. A new forum can be found here.

C/C++ > Makefile - Confusing error msg

#10965 - Ruiner - Mon Sep 22, 2003 2:54 am

New to makefiles. I have always used visual studio so this is all new to me. Here is the error I am getting.
Code:

c:/devkitadv/bin/gcc -c source/main.cpp -obin/main.o -I./data -I./include -Ic:/devkitadv/lib/gcc-lib/arm-agb-elf/3.2.2/include -IC:/devkitadv/arm-agb-elf/inclue -mthumb -mthumb-interwork -c -g -Wall -fverbose-asm

c:\Docume~1\Therui~1\Locals~1\Temp/ccUxaaaa.s: Assembler messages:
c:\Docume~1\Therui~1\Locals~1\Temp/ccUxaaaa.s:1029: Error: invalid offset value to big (0xFFFFFFF8)
make: *** [bin/main.o] Error 1

Can anyone help me figure out how to fix it? It compiles fine with my old makefile but I decided to modify it learning from the SGADE makefile because I wasn't sure how to add in crt0.o and link in includes on my own.

The main changes from what I had before are from this:
CFLAGS = -c -O -I $(INCDIR2) -I $(INCDIR) -g -O2
to this:
C_FLAGS = -I$(DAT_DIR) -I$(INC_DIR) -mthumb -mthumb-interwork -c -g -Wall -fverbose-asm

and linked with this.
L_FLAGS = -T $(LINK_SCRIPT_DIR)/lnkscript -lg -lc -lgcc

#10966 - sajiimori - Mon Sep 22, 2003 5:27 am

Hopefully somebody else will have a real answer, but here's at least a start.

Forget about the linker for the moment, because the compile isn't getting that far. It's also not make's fault.
Quote:

C_FLAGS = -I$(DAT_DIR) -I$(INC_DIR) -mthumb -mthumb-interwork -c -g -Wall -fverbose-asm

If -fverbose-asm, -mthumb, and -mthumb-interwork are the new additions, then try removing those. If it works after that, let us know.
Quote:

-IC:/devkitadv/arm-agb-elf/inclue

Typo? Probably not relevant to the error, though.

Just a guess, but try adding -mlong-calls to cflags.

#11008 - Ruiner - Tue Sep 23, 2003 10:51 am

Ok, I fixed the problem by removing crtbegin and crtend which i read you have to include if you wanted to use c++. I really have no clue what they are but it works w/o them. So now I want to know if that was being caused by -mthumb interwork then what have i possibly done wrong in my code that is preventing thumb code from compiling?

#11037 - sajiimori - Wed Sep 24, 2003 12:10 am

I don't know how the error could have been fixed by changing your linker options, since the error you posted was from the assembler (which is used before the linker).

I also don't know why you would think -mthumb-interwork was causing the problem, if you already solved it by changing your linker options.

In other words, I have no idea what you're talking about. :-/

BTW, try using g++ instead of gcc when compiling C++ code, so it'll automatically link in the right stuff (no need to worry about crts).

#11113 - Ruiner - Fri Sep 26, 2003 4:55 am

Erm, man i need to smack myself about the head a few times here and there. Im sorry I was probably typing on nyquil while my wife was talking to me and my daughter was screaming. My family has been sick for the past week straight and its a mad house. Im surprised I get anything done :)

Ok I removed the -mthumb first and it assembled but I got another error. I removed crtbegin and end and it compiled and worked beautifully. So what I was wanting to know was what might be happening to cause -mthumb interwork to make that error.

And now I also want to ask what crtbegin and end is? I was only copying them over because there was a paragraph saying you had to include them in a c++ project.

Finally if g++ links everything correctly then will I need to include everything that needs to be linked in my g++ command line or is it automagical detecting what I have included in my headers? My project is separated in diferent folders and my current setup allows me to compile w/o having to specify which folder each include is in.

Code:

# PROJECT
# --------------------------------------------------------------------
ROM = project.gba
ELF = project.elf

# Visual Boy Advance Directory
# --------------------------------------------------------------------
VBA = C:\Documents and Settings\The Ruiner\My Documents\GB\VisualBoyAdvance.exe
GDB = C:\Documents and Settings\The Ruiner\My Documents\GB\arm-gdb.exe

# GCC Directories for Includes
# --------------------------------------------------------------------
GCC_VERSION = 3.2.2
GCC_DIR  = C:/devkitadv
STD_LIB_DIR0 = $(GCC_DIR)/lib/gcc-lib/arm-agb-elf/$(GCC_VERSION)/interwork
STD_LIB_DIR1 = $(GCC_DIR)/arm-agb-elf/lib/interwork
STD_INC_DIR0 = $(GCC_DIR)/lib/gcc-lib/arm-agb-elf/$(GCC_VERSION)/include
STD_INC_DIR1 = $(GCC_DIR)/arm-agb-elf/include

# Project Directories for Includes
# --------------------------------------------------------------------
PROJECT_DIR      = .
INC_DIR         = $(PROJECT_DIR)/include
SRC_DIR         = $(PROJECT_DIR)/source
CRT0_S_DIR      = $(PROJECT_DIR)
LINK_SCRIPT_DIR = $(PROJECT_DIR)
OBJ_DIR         = $(PROJECT_DIR)/bin
ELF_DIR         = $(PROJECT_DIR)/bin
DAT_DIR         = $(PROJECT_DIR)/data

# Flags for Compiler, Assembler, and Linker (thumb smaller, arm faster)
# --------------------------------------------------------------------
C_FLAGS  = -I$(DAT_DIR) -I$(INC_DIR) -I$(STD_INC_DIR0) -I$(STD_INC_DIR1) -c -g -Wall -mlong-calls
S_FLAGS  = -I$(DAT_DIR) -I$(INC_DIR) -I$(STD_INC_DIR0) -I$(STD_INC_DIR1)
L_FLAGS = -L$(STD_LIB_DIR0) -L$(STD_LIB_DIR1) -T $(LINK_SCRIPT_DIR)/lnkscript  -lstdc++ -lgcc -lc

# List of compiled Object files before they get linked
# --------------------------------------------------------------------
CRT0_O         = $(OBJ_DIR)/crt0.o
#CRTBEGIN_O      = $(STD_LIB_DIR0)/crtbegin.o
#CRTEND_O      = $(STD_LIB_DIR0)/crtend.o
LIST         = $(patsubst $(SRC_DIR)/%.cpp, %.o, $(wildcard $(SRC_DIR)/*.cpp))
O_FROM_LIST      = $(addprefix $(OBJ_DIR)/, $(LIST))
O_FILES         = $(CRT0_O) $(CRTBEGIN_O) $(CRTEND_O) $(O_FROM_LIST)


# Goal of the make file. Produce $(ROM) in $(PROJECT_DIR)
# --------------------------------------------------------------------
all: $(PROJECT_DIR)/$(ROM)
   @echo "Done."

# PARAM: (clean) - clean the directory of .elf and .o files
# --------------------------------------------------------------------
clean:
   @echo ""
   @echo "----------------------------------"   
   @echo "- Cleaning Directory"
   @echo "----------------------------------"   
   rm -f $(ELF_DIR)/*.elf
   rm -f $(OBJ_DIR)/*.o

# PARAM: (run) - after compiling run the rom on VisualBoy
# --------------------------------------------------------------------
run: $(PROJECT_DIR)/$(ROM)
   @echo ""
   @echo "----------------------------------"
   @echo "- Running VisualBoy ($(ROM))"
   @echo "----------------------------------"   
   $(VBA) $<
   
# PARAM: (debug) - after compiling run the rom on VisualBoy using GDB/Insight
# --------------------------------------------------------------------
debug:
   @echo ""
   @echo "----------------------------------"
   @echo "- Debug not implemented yet"
   @echo "----------------------------------"


# ********************************************************************
# * COMPILATION BELOW                                                *
# ********************************************************************

# Copy .elf to .gba
# --------------------------------------------------------------------
$(PROJECT_DIR)/$(ROM): $(ELF_DIR)/$(ELF)
   @echo ""
   @echo "Copy"
   @echo "----------------------------------"
   $(GCC_DIR)/bin/objcopy -v -O binary $< $@

# Link the project;
# -----------------------------------------------------------------------------
$(ELF_DIR)/$(ELF) : $(O_FILES)
   @echo ""
   @echo "Link"
   @echo "----------------------------------"
   $(GCC_DIR)/bin/ld  $(O_FILES) -o./$@ $(L_FLAGS)
   
# Assembly of source files;
# -----------------------------------------------------------------------------
$(O_FROM_LIST) : $(OBJ_DIR)/%.o : $(SRC_DIR)/%.cpp
   @echo ""
   @echo "Assemble"
   @echo "----------------------------------"
   $(GCC_DIR)/bin/gcc  -c $< -o$@ $(C_FLAGS)    

# Define the assembly of the crt0 file;
# -----------------------------------------------------------------------------
$(CRT0_O) : $(OBJ_DIR)/%.o : $(CRT0_S_DIR)/%.S
   @echo ""
   @echo "Assemble crt0.o"
   @echo "----------------------------------"
   $(GCC_DIR)/bin/gcc -c $< -o$@ $(S_FLAGS)

#11114 - sajiimori - Fri Sep 26, 2003 5:34 am

I still don't understand. What problem is -mthumb-interwork causing?

crtbegin/end are startup/shutdown code used by gcc. They are normally linked in automatically by gcc or g++, as appropriate.

g++ doesn't do anything weird, like read your headers or anything. It just sets the flags and links in the stuff that C++ apps need in general, like modules for exception handling.

#11118 - Ruiner - Fri Sep 26, 2003 3:05 pm

Ok, the first error. The error that started this post. I add -mthumb -mthumb-interwork to $(C_FLAGS) and I get THAT message. I remove it and its fine.

Once its removed if I have $(CRTBEGIN_O) and $(CRTEND_O) uncommented so it gets added to $(O_FILES) then i get an error stating that my project.elf supports interworking but main.o (i think it was main.o) does not.

Quote:
c:\Docume~1\Therui~1\Locals~1\Temp/ccUxaaaa.s: Assembler messages:
c:\Docume~1\Therui~1\Locals~1\Temp/ccUxaaaa.s:1029: Error: invalid offset value to big (0xFFFFFFF8)


Its diferent every time though. Like this last time it was cc6faaaa.s:941: rather than ccUxaaaa.s:1029:

#11128 - sajiimori - Fri Sep 26, 2003 6:51 pm

Hmm...can you email me a source file that has the problem? (myname)@hotmail.com