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++ > Problem Compiling Intro Example

#159227 - Jubb - Fri Jun 27, 2008 6:44 pm

I'm trying to follow the "Introduction to Nintendo DS Programming" project on patater.com and I'm running into some strange compile time errors. First of all, forgive me if this is the wrong place to ask I don't know where else I could. Also, just a warning, the problem is probably completely newbish, I'm sure it is something simple I have just overlooked.

I used LOANI to install devkitpro and a few other things on my linux box, then I downloaded and compiled GRIT but I'm not sure if I installed it correctly for the purposes of this project because to get the makefile to recognize it I just copied the executable alone to my devkit/bin folder and I'm not sure if that's all I needed to do.

Now when I try to compile the code from "Chapter-0-Starting System" that I basically copied from the tutorial, I get a ton of compile time errors saying pretty much everything in the program was not declared in this scope. Here's a few lines of it to give you an idea.


Code:
: In function 'int main()':
/workspace/NDS/manual/code/chapter_0-starting_system/source/main.cpp:18: error: 'initVideo' was not declared in this scope
/workspace/NDS/manual/code/chapter_0-starting_system/source/main.cpp:19: error: 'initBackgrounds' was not declared in this scope


I have dabbled in C/C++ coding before and I checked all my parentheses so that's not the problem. If you guys want me to post the whole program I will, I just figured this post was already long enough.

Thanks for even reading this

#159279 - Jubb - Sat Jun 28, 2008 5:33 pm

Over 30 views and no reply? Am I asking that stupid of a question?

#159283 - silent_code - Sat Jun 28, 2008 5:51 pm

Um... Hi!
Welcome to the scene. :^)

...

Well, the situation is the following: You are working with Linux, you're using an otherwise good tutorial, which unfortunately is known to cause trouble with recent libnds releases (just replace the rotoscale matrix id macro with the id and you'll be fine)... and also your description may be too unspecific in some parts, e.g.: What header files do you include? How do you compile (via makefile, some IDE, manually or a shell script)?

I really don't know... there are many possibilities why it doesn't work and I just have experience with the Windows (= dark) side of the for... of devkitARM. Sorry.

But I'm positive that your question will be answered if you elaborate a little bit and be patient.

Good luck and have a nice day! :^)

EDIT: Post the source of what's not compiling. ;^)
_________________
July 5th 08: "Volumetric Shadow Demo" 1.6.0 (final) source released
June 5th 08: "Zombie NDS" WIP released!
It's all on my page, just click WWW below.


Last edited by silent_code on Sat Jun 28, 2008 7:56 pm; edited 1 time in total

#159289 - zeruda - Sat Jun 28, 2008 7:35 pm

The error is self explanatory.

: In function 'int main()':
In your main function:

/workspace/NDS/manual/code/chapter_0-starting_system/source/main.cpp:18:
on line 18:

error: 'initVideo' was not declared in this scope
You're using something called initVideo, but it hasn't been declared in this scope. In other words, main() can't see anything called initVideo

What I suggest is you post the lines that are causing the error. You also should post the declaration of initVideo and initBackgrounds. I assume they are functions. Are they declared in the same .cpp file as your main() function? If so are they written above it or below? If below you need to declare a funtion prototype above the main function or cut and paste the functions from below to above.
If not which file are they declared in? Have you included that file?

If you're still stuck post all your code.

#159299 - Jubb - Sat Jun 28, 2008 10:08 pm

Thank you guys very much for the replies, I was following that tutorial a little too absent-mindedly and didn't notice those functions were written after my main.
The only thing that doesn't seem to be working now are the variables that the program uses that I thought grit defined for me. I've never used grit before so I'm not sure what to expect but the tutorial never explicitly said to declare these variables anywhere else in the code.

The error messages look like this :

Code:
/NDS/manual/code/chapter_0-starting_system/source/main.cpp: In function 'void displayStarField()':
/NDS/manual/code/chapter_0-starting_system/source/main.cpp:74: error: 'starFieldBitmap' was not declared in this scope
/NDS/manual/code/chapter_0-starting_system/source/main.cpp:76: error: 'starFieldBitmapLen' was not declared in this scope


It seems to be a problem with how I installed Grit then because the code (I copied from the tutorial) looks like this.

Code:
void displayStarField() {
    dmaCopyHalfWords(DMA_CHANNEL,
                     starFieldBitmap, /* This variable is generated for us by
                                       * grit. */
                     (uint16 *)BG_BMP_RAM(0), /* Our address for main
                                               * background 3 */
                     starFieldBitmapLen); /* This length (in bytes) is generated
                                           * from grit. */
}



Any advice?

#159300 - gmiller - Sat Jun 28, 2008 10:48 pm

The two variables are unknown to the compiler ... either they are in a header file with the data (not a great way to do this) or they are in a separately compiled file so you need to insert "extern" declaration of these variables in your code to allow the compiler to set things up so the linker can find them.

Having never used "grit" I do not know the conventions used by the utility. If it creates a source file and a header file you might just need to include the header in your main and make sure the souce file is compiled as part of your project. If it only produces a header file with the data in it then you could just "#include" it in your "main" source file. Generally #including data is not looked on as favorably as separately compile and link but whatever floats your boat at this point could work.

I push for separately compiled source and a a header file with the externs declared in it. If you use the const keyword and use C++ you will need an extern declaration in the source file to make sure the compiler does not drop all of your data.

BTW: From the devkit pro information:
Quote:

The header file "tilemap.h" is generated by grit and can be found in the build folder. The names are generated from the filename of the bmp so, for a tiled image like this we end up with a few variables defined.

<filename>Pal - address of the palette data
<filename>PalLen - size of the palette data in bytes
<filename>Tiles - address of the tile data
<filename>TilesLen - size of he tile data in bytes
<filename>Map - address of the map data
<filename>MapLen - size of the map in bytes


So you should #include the tilemap.h in your source file.

#159306 - Jubb - Sun Jun 29, 2008 12:26 am

Oh, I didn't know devkit had info about grit and grit's own website didn't have much in the way of help. Thank you all for your advice, you were very helpful.