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.

Coding > Problems compiling with multible .c/.cpp files

#78983 - Kaiser - Tue Apr 11, 2006 12:30 am

I have 5 files, two cpp files, and three .h files. One h file contains all the register information like video memory definitions etc. I have a source file which contains the main function and the other source file contains a printing function.

Bascially both source files relies on the .h file with all the register/video defintions. My main function calls the printing funtion. When I try to compile, it complains about multible defintions of the definitions defined in my register/video header file.

Basically it won't let me call the definitions from my video/register header file from two different source files.

I appriciate the help. Also I can post the source code if needed.

Here is my batch file used to compile.

Code:

@echo off
REM just add  .c file and  .o file to the next two lines
set SRC=E:\devkitPro\LWizard\Source\
set CFILES=%SRC%g_main.cpp %SRC%g_printf.cpp
set OFILES=g_main.o g_printf.o


set GAME= LWIZARD
set SPECS=gba.specs
set OUTPUT=E:\devkitPro\LWizard\LWIZARD.gba

set DEVDIR=E:\devkitPro
set DATADIR=E:\devkitPro\LWizard\Include

PATH=%DEVDIR%\bin;%path%

REM set our paths so the linker knows were to look for the libs
set LIBDIR= %DEVDIR%\arm-elf\lib\interwork
set LIBDIR2= %DEVDIR%\libgba\lib

REM set our include directories so the compiler can find our include files
set INCDIR= %DEVDIR%\arm-elf\include
set INCDIR2= %DATADIR%

REM the compiler and linker flags
set CFLAGS= -I.  -I%INCDIR% -I%INCDIR2% -c -g -O2 -Wall -mcpu=arm7tdmi -mtune=arm7tdmi

-fomit-frame-pointer -ffast-math -mthumb -mthumb-interwork

set LDFLAGS=  -mthumb -mthumb-interwork -specs=%SPECS% -L%LIBDIR% -L%LIBDIR2% 

REM Compile the cfiles
E:\devkitPro\devkitARM\bin\arm-elf-gcc.exe  %CFILES% %CFLAGS%

REM link the o files
E:\devkitPro\devkitARM\bin\arm-elf-gcc.exe -o %GAME%.elf  %OFILES% %LDFLAGS%

REM gcc produces .elf exicutables...objcopy to .gba
E:\devkitPro\devkitARM\bin\arm-elf-objcopy.exe -v -O binary %game%.elf %OUTPUT%

E:\devkitPro\devkitARM\bin\gbafix.exe %OUTPUT%

REM remove all the ofiles
del %game%.elf

pause

#78989 - poslundc - Tue Apr 11, 2006 12:45 am

Post the error you are getting.

Dan.

#78990 - Kaiser - Tue Apr 11, 2006 12:51 am

[Images not permitted - Click here to view it]

just to let you know oamPtr, bakPtr etc are all defined on that same .h file.

#79000 - poslundc - Tue Apr 11, 2006 2:03 am

Don't put data in your header files.

Dan.

#79002 - Kaiser - Tue Apr 11, 2006 2:04 am

haha and I was just looking at that thread though a search too.

Thanks.