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.

DS development > Including a file

#49306 - MasterRay - Thu Jul 28, 2005 12:03 pm

This must be a very simple question, but nevertheless I can't solve it.
I'm using the latest DevEnv 3.0.1.
I have a main.cpp and a data.h, when I use #include "data.h" I get these errors:
built ... arm7.bin
main.cpp
c:/ndsdev/projects/LogicGates/arm9/source/main.cpp:13: error: new types may not be defined in a return type
c:/ndsdev/projects/LogicGates/arm9/source/main.cpp:13: error: extraneous `int' ignored
c:/ndsdev/projects/LogicGates/arm9/source/main.cpp:13: error: `main' must return `int'
c:/ndsdev/projects/LogicGates/arm9/source/main.cpp:13: error: return type for `main' changed to `int'
make[2]: *** [main.o] Error 1
make[1]: *** [build] Error 2

> Process Exit Code: 0

I can't understand why it can't include the file, I hope you can help me.

Sorry, I've just solved the problem by myself
No need to reply

#49307 - NoMis - Thu Jul 28, 2005 12:07 pm

Seems like you have errors in your main function rather then with including the file. Seeing your main function might be helpfull to further investigate the error.

NoMis
_________________
www.gamedev.at - The austrian gamedev site
hde.gamedev.at - The Handheld Dev Env plugins for Eclipse

#49308 - MasterRay - Thu Jul 28, 2005 12:17 pm

I had a simple error in my include file

#49309 - NoMis - Thu Jul 28, 2005 12:27 pm

MasterRay wrote:
I had a simple error in my include file


The error output you provided tells me the error is in main.cpp row 13 and has something to do with your main function.

MasterRay wrote:
c:/ndsdev/projects/LogicGates/arm9/source/main.cpp:13: error: new types may not be defined in a return type
c:/ndsdev/projects/LogicGates/arm9/source/main.cpp:13: error: extraneous `int' ignored
c:/ndsdev/projects/LogicGates/arm9/source/main.cpp:13: error: `main' must return `int'
c:/ndsdev/projects/LogicGates/arm9/source/main.cpp:13: error: return type for `main' changed to `int'


We need further information to help you. The error output of the compiler tells us nothing. Send some code snippets of the places where the error happened. What is you include file containing.

NoMis
_________________
www.gamedev.at - The austrian gamedev site
hde.gamedev.at - The Handheld Dev Env plugins for Eclipse

#49311 - MasterRay - Thu Jul 28, 2005 1:12 pm

I've found the error already, I had a semicolon missing in the include file, but since it told me that the error was in the main file I looked there.

#49315 - MasterRay - Thu Jul 28, 2005 4:53 pm

I came to another problem:
I'm trying to add my own sprites, I've drawn something and I use gfx2gba so it turned to *.pal and *.raw, how do I convert them to *.h or *.o so I can use them within my application?

#49318 - tepples - Thu Jul 28, 2005 5:16 pm

Try 'bin2s' included with GBFS. It'll convert any binary file to an assembly language (*.s) file that contains the same data, which you can then compile to an object code file (*.o).
_________________
-- Where is he?
-- Who?
-- You know, the human.
-- I think he moved to Tilwick.

#49331 - MasterRay - Thu Jul 28, 2005 8:13 pm

But I saw that the demos, for example: UnderPressure, use *.h files and not *.o

#49332 - natrium42 - Thu Jul 28, 2005 8:20 pm

MasterRay wrote:
But I saw that the demos, for example: UnderPressure, use *.h files and not *.o

Yes, it's better to not use bin2s. Put your ressource files into data/ folder and the Makefile will automatically create a header file for each ressource. Linker will link the ressources into the final binary.

Look for bin2o in the Makefile if you want to see the mechanism.
_________________
www.natrium42.com

#49338 - MasterRay - Thu Jul 28, 2005 10:28 pm

I've added the files to a folder names 'data', and the compiler seem to have found them, but I got a new error message:
built ... arm7.bin
img.o: In function `img':
: multiple definition of `img'
img.o:: first defined here
img.o: In function `img_end':
: multiple definition of `img_end'
img.o:: first defined here
collect2: ld returned 1 exit status
make[2]: *** [/c/ndsdev/projects/img/arm9/arm9.elf] Error 1
make[1]: *** [build] Error 2

What is the problem?

#49350 - natrium42 - Fri Jul 29, 2005 12:46 am

You can't have a function name and a variable name be the same. I think that's your problem.
_________________
www.natrium42.com

#49395 - MasterRay - Fri Jul 29, 2005 10:37 am

I have done nothing with the template I have only 'int main', and that's it, in the data folder I have: img.pal and img.raw, these are the only files. I haven't changed any line from the makefile.
Yet, the problem remains, what can I do?

#49408 - natrium42 - Fri Jul 29, 2005 3:02 pm

MasterRay wrote:
I have done nothing with the template I have only 'int main', and that's it, in the data folder I have: img.pal and img.raw, these are the only files. I haven't changed any line from the makefile.
Yet, the problem remains, what can I do?

Hm, perhaps the Makefile changed. Try to rename img.pal to img_pal.pal. Perhaps you can't have the same basenames for data files.
_________________
www.natrium42.com

#49413 - MasterRay - Fri Jul 29, 2005 4:50 pm

Almost there, I have now an img.h file and I try to present it as a sprite, I've taken the demo that creates three sprites on the screen and I want to make the first sprite my image. I've copied the line:
for(int i=0;i<32*32;i++)
SPRITE_GFX[i]=((u16*)img)[i] | BIT(15); //dont forget alpha bit
from another example.
But now all I get is:
built ... arm7.bin
main.cpp
main.o: In function `main':
c:/ndsdev/projects/LogicGates/arm9/source/main.cpp:139: undefined reference to `img'
collect2: ld returned 1 exit status
make[2]: *** [/c/ndsdev/projects/LogicGates/arm9/arm9.elf] Error 1
make[1]: *** [build] Error 2
Everything is exactly the same instead that line, what is the problem now?
Thanks for all of your help.

#49415 - natrium42 - Fri Jul 29, 2005 5:09 pm

Did you include that header file? Look in the header file to make sure you are using the correct variable name.
_________________
www.natrium42.com

#49417 - tepples - Fri Jul 29, 2005 5:18 pm

natrium42 wrote:
Yes, it's better to not use bin2s. Put your ressource files into data/ folder and the Makefile will automatically create a header file for each ressource. Linker will link the ressources into the final binary.

Look for bin2o in the Makefile if you want to see the mechanism.

If it uses objcopy, then it will likely have alignment problems. Last time I tried objcopy, it had no way to specify an alignment larger than one byte. Using bin2s guarantees a 4-byte alignment.
_________________
-- Where is he?
-- Who?
-- You know, the human.
-- I think he moved to Tilwick.

#49425 - natrium42 - Fri Jul 29, 2005 6:15 pm

bin2o pads the file and I think the linker aligns the array but I am not sure. Didn't have any problems so far, though.
Code:
define bin2o
   padbin 4 $(<)
   $(OBJCOPY) -I binary -O elf32-littlearm -B arm \
   ...
endef

_________________
www.natrium42.com

#49431 - tepples - Fri Jul 29, 2005 6:46 pm

natrium42 wrote:
bin2o pads the file and I think the linker aligns the array

to a 1-byte boundary. The 'padbin' utility pads only the end of the file; if the last thing in .rodata before the first padbin+objcopy object is a 'char' or 'short' that doesn't happen to end up on a 4-byte boundary, then all the padbin+objcopy objects will still end up unaligned.

If you disagree with the whole-path behavior of bin2s, then modify it to use the basename behavior of gbfs.
_________________
-- Where is he?
-- Who?
-- You know, the human.
-- I think he moved to Tilwick.

#49437 - natrium42 - Fri Jul 29, 2005 7:04 pm

tepples wrote:
natrium42 wrote:
bin2o pads the file and I think the linker aligns the array

to a 1-byte boundary. The 'padbin' utility pads only the end of the file; if the last thing in .rodata before the first padbin+objcopy object is a 'char' or 'short' that doesn't happen to end up on a 4-byte boundary, then all the padbin+objcopy objects will still end up unaligned.

I know that, hence the "I think the linker aligns the array but I am not sure"
_________________
www.natrium42.com