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 > GCC problem, please help

#3040 - Jer1400 - Mon Feb 17, 2003 3:44 am

I've just started GBA development and I'm in a bit of trouble already. You see, I am using the GCC development kit along with MSVC++ to create .bin roms. The only problem is...it doesn't work. I did everything the tutorial told me to do, but everytime I try to build the .bin rom, my computer totally locks up. It worked once, and I'm not quite sure why, but then it continued to freeze. These are the instructions I followed:

Ok, now that you have installed Visual C++ 6.0, start it up. We are now going make a test compile, so go to "File" and select "New" (or just push Ctrl+N). Open up the "Projects" tab (if it's not already open), and select "MakeFile". Under "Project name:", write "CPPTest". On "Location:", I have written "C:\GBADEV\" as my default location, but you can use any other that you see fit. I always like to make it clean and easy to remember though.

Remember that the project, which is named "CPPTest" will make a new directory called "CPPTest", in the GBADEV-folder. In other words, the test file we are going to compile, and all the files within this project will be located in the "C:\GBADEV\CPPTest\" directory. Make sure the "Win32" box is ticked under "Platforms:", and that "Create new workspace" is selected. Now click "OK". Look at the place where it says "Output:". Since the ROM-images we are going to make isn't an .exe but a .bin, we will have to rename it. Make sure it says "CPPTest.bin", and click on "Next". Do the same thing once again, and click "Finish".

"New Project Information" will appear. Just close it by clicking "OK". We are now ready to modify Visual C++ a bit so that it will use the Development Kit that we have downloaded (if you haven't already, check the "Downloading and installing the Development Kit"-part, and do that before you continue). In the "Tools" drop down menu, select "Options". Open up the "Directories"-tab. Under where it says "Show directories for:", it should say "Include files". Change it to "Executable files". A new list of folders will appear. At the very bottom, click twice and write in the location of the Development Kit. In my case, I have installed the kit under C:\GBA, so that's what I'll write as my location. I will also have to put "\bin" at the end to, so the correct location would be "C:\GBA\bin". Remember not to add a \ at the end of the location (like "C:\GBA\bin\"), or it might not work. Push "ok".

Now, let's make use of the CPPTest files included in the ZIP file of this document. Go to the folder where you unzipped it, and locate the folder names "Files", then "CPPTest". The folder should contain the following files:
boot.s
CPPTest.mak
ctrbegin.o
crtend.o
Linkscript
main.cpp

Copy and paste all these files into the CPPTest folder (my location at C:\GBADEV\CPPTest). When that's done, let's get a better overview of the files we have in our folder. In Visual C++, look at the middle window at the left side. There are two "tabs" in the bottom, called "ClassView" and "FileView". Click on the "FileView" tab. Notice the change in the window above. Now click on the [+] next to the "CPPTest files" directory icon, and you will notice three folders. This is the place where we will add our files so that we can easily access them and edit them as we find it appropriate. To add the files, left click on the "CPPTest files" directory icon, and choose "Add Files to Project?" from the menu that appears. It will as default choose to include C++ files, so the only thing showing here should be "main.cpp". Change "Files of type" to "All files". You can now get a look at every file placed within the workspace directory (note the name "workspace directory"). Now, with Ctrl pushed, click on "boot.s", "Linkscript", "CPPTest.mak" and "main.cpp". Once all of these are selected, push OK. Notice that the files now seem to appear at the left window (workspace window), under the folders. If you look closely though, you will notice that "main.cpp" is gone. Well, it isn't. Visual C++ has recognized the file as a source file, and placed it in the appropriate folder. Click on the [+] next to the "Source Files" folder to make sure it is in its right place. Now, before we move on, let me tell you a bit about the workspace window, and the reason to include files here.

The workspace window is quite handy, and is one of the main reasons why developers uses and IDE instead of just writing everything in for instance "Notepad" or "Dos-Edit" (that, and the fact that an IDE gives you error outputs - more on that later). To include files in this windows, just Right-Click and select "Add Files to Project?", then locate your files. The files will then be placed in their appropriate folders, for easy location later. Files that the Visual C++ does not recognize, will be placed underneath the folders. An assumption often made by newbie-programmers (like myself) is that it is the files in the workspace directory that determines what is compiled in the final output (in this case, the .bin file - GBA rom). This is certainly not the case. The files in the directory are just a way to have easy access. To access a file and its content, just double-click it, and it will appear in a window at the right side of the workspace window. You can then easily edit the code. A good rule is to always close the window of the file you are working on, if you are to open up another. That way, you can avoid having to codes open at once, since it doesn't save the code if you don't close it. You will also avoid having multiple windows of the same code, making it hell on earth to edit.

So, what is compiled then? Well, the file called "CPPTest.mak" keeps track on that. And since we're going to use it in this case, let's open it up now, as it needs some editing. Double-click on it, and its source should appear in all its glory. Look for the place where it says "SRCDIR = G:\GBA\CPPTest". Let me explain why this is not the right directory to use in our case; we put the Development Kit in the C:\GBA directory (at least I did), and what the SRCDIR is looking for is actually the Source Directory (whoa, you saw it right away, right?). Change it to "C:\GBADEV\CPPTest" instead, and this time, make damned sure not to add a "\" in the end there, as it will make the compiler go crazy (well, it won't work anyway). Also, note that it is on G: at default, so make sure you don't forget to change it. All the other directories (the five below the one we just changed) are looking for certain things in the development kit it needs to compile the program. Let's change it so that it fits our setup. Again, I will use my location, just alter it as you see fit. In "CMPDIR = G:\DevKitAdv\bin", just change the "G:\DevKitAdv\" part so it says "C:\GBA\". Alter it so that it reads this at the end:

SRCDIR = C:\GBADEV\CPPTest
CMPDIR = C:\GBA\bin
LIBDIR = C:\GBA\lib\gcc-lib\arm-agb-elf\3.0.2\interwork
LIBDIR2 = C:\GBA\arm-agb-elf\lib\interwork
INCDIR = C:\GBA\lib\gcc-lib\arm-agb-elf\3.0.2\include
INCDIR2 = C:\GBA\arm-agb-elf\include

If you are in a hurry, you could just copy paste this, but I highly recommend that you punch it in manually, as that is the only way to learn it. There is no shortcut to learning, my friend ;) Now that all that is done, close the SourceView window. Notice that it doesn't ask you to save, just assume so and writes straight to the file (you can't "undo" anything after this).

Ok, we are now set to compile our first program. If you want to take a look at the source code for what we are about to compile, just open up "main.cpp" in the workspace directory. Not much code, eh? Well, wonder what the result will be? Maybe a new Mario game, or perhaps the sequel to Half-Life? Go to the "Build" drop-down menu and select "Rebuild All". The compiler will take it's time, compiling the source code. You can see it in action by looking at the bottom window, compiling and linking the files needed. When it's done, it should say "CPPTest.bin - 0 error(s), 0 warning(s)" (if you don't get this message, you got a problem - see the "Aaarg!"-section for help). This means that the .bin file has been made. That's right, your very first GameBoy Advance rom has been compiled (ok, so the code isn't done by you, but you still did something!), and you can now play it on your favorite emulator. Open it up, and fire away! The rom is located in the CPPTest folder, by the way.

I won't tell you what the end result is, but if you have been using windows for a long time, the result should bring back memories :p

**
**End Instructions**
**

So I followed those instructions, and it froze. I'm using windows ME, and I've reinstalled everything multiple times already. Any tips, ideas or anything at all would really help and is very much appriciated. Thanks you in advance.:)

Ps.

I'm sorry if this is a bit offtopic but I didn't see a board for general development.
_________________
http://saoghal.cywh.com/Jer1400/index.html

*Note that the site is still in early development.

#3050 - pollier - Mon Feb 17, 2003 8:36 am

Exactly where did it freeze? Can you get some compiler output before it locks up, or is VC++ doing this to you--or is it the emulator? Perhaps you should try running some of the binaries in your (possibly) C:\GBADEV\BIN folder and see if they act strangely...

Hope this helps,
_________________
(Works for me!)

#3051 - Lionheart - Mon Feb 17, 2003 8:39 am

I also have WinME and it Froze at OBJCOPY. The Solution for me was: shut down all the background programs. Hope it will also work for you.

#3065 - Saj - Mon Feb 17, 2003 3:36 pm

I'm using Visual C++ 6 with DevkitAdvance and I set it up by using GBA Project Appwizard.

you can get it at :

http://www.gbadev.org/files/GBA_AW_r2-6_Setup.txt

It does all the setting-up for you with just a couple of clicks of yer mouse
button.

Hope this helps.

#3069 - Jer1400 - Mon Feb 17, 2003 5:45 pm

Erm, saj? That's a .txt file. Did you mean .zip? And here is what it gives me. It freezes right after I hit "build ******.bin." It says some stuff, and then locks up. It does say something about obj copy, I think. But then it locks up and the .plg (I think that's the right format) anyway, the file that's an html document, you know? Well, it is always empty but it says (before it freezes) some other stuff. If I can I'll try to post it later today.
_________________
http://saoghal.cywh.com/Jer1400/index.html

*Note that the site is still in early development.

#3078 - Saj - Mon Feb 17, 2003 8:01 pm

My bad...Sorry about that..
try this:-

http://www.gbadev.org/download.php?section=misc&filename=GBA_AW_r2-6_Setup.zip

#3097 - Jer1400 - Tue Feb 18, 2003 6:14 am

Okay, thanks saj. I'll try it tomorrow. But in case it doesn't work, here is where I am now:

Okay, I tried it again and this is what I got after closing everything else. (Thanks for the tip)

The first time it froze and I wrote down and then typed this:

----------Configuration: CPPTest - Win32 Debug------------
Microsoft (R) Program Maintenance Utility Version 6.00.8168.0
Copyright (C) Microsoft Corp 1988-1998. All rights reserved.
objcopy -v -o binary CPPTest.elf CPPTest.bin
cope from CPPTest.elf (elf32-littlearm) to CPPtest.bin (binary)

The second time I did it after I turned my computer back on and closed all other programs it did not freeze, but it still had an error. The only thing I did different was take out the old CPPTest.bin file from that one time it worked and put it on my desktop. The .bin rom wasn't created, and this is what it told me:

--------------------Configuration: CPPTest - Win32 Debug--------------------



Microsoft (R) Program Maintenance Utility Version 6.00.8168.0
Copyright (C) Microsoft Corp 1988-1998. All rights reserved.

gcc -I C:\GBA\arm-agb-elf\include -I C:\GBA\lib\gcc-lib\arm-agb-elf\3.0.2\include -I C:\GBADEV\CPPTest -mthumb-interwork -c -g -O2 -Wall -fverbose-asm C:\GBADEV\CPPTest\main.cpp
Linkstub failed (/cygdrive/c/GBADEV/CPPTest/gcc -> arm-agb-elf-gcc) = /cygdrive/c/GBADEV/CPPTest/arm-agb-elf-gcc: No such file or directory
Thought that link path (arm-agb-elf-gcc) was a relative path.
Thought that argv[0] (/cygdrive/c/GBADEV/CPPTest/gcc) was an absolute path.
NMAKE : fatal error U1077: 'C:\GBADEV\CPPTest\gcc.exe' : return code '0xffff'
Stop.
Error executing nmake.



Results
CPPTest.bin - 1 error(s), 0 warning(s)

So then I took what it told me and made some new directories with gcc.exe in them. Those directories were C:\GBADEV\CPPTest\gcc and C:\GBADEV\CPPTest\arm-agb-elf-gcc. So then it gave me this error:

--------------------Configuration: CPPTest - Win32 Debug--------------------



Microsoft (R) Program Maintenance Utility Version 6.00.8168.0
Copyright (C) Microsoft Corp 1988-1998. All rights reserved.

gcc -I C:\GBA\arm-agb-elf\include -I C:\GBA\lib\gcc-lib\arm-agb-elf\3.0.2\include -I C:\GBADEV\CPPTest -mthumb-interwork -c -g -O2 -Wall -fverbose-asm C:\GBADEV\CPPTest\main.cpp
Linkstub failed (/cygdrive/c/GBADEV/CPPTest/gcc -> arm-agb-elf-gcc) = /cygdrive/c/GBADEV/CPPTest/arm-agb-elf-gcc: No such file or directory
Thought that link path (arm-agb-elf-gcc) was a relative path.
Thought that argv[0] (/cygdrive/c/GBADEV/CPPTest/gcc) was an absolute path.
NMAKE : fatal error U1077: 'C:\GBADEV\CPPTest\gcc.exe' : return code '0xffff'
Stop.
Error executing nmake.



Results
CPPTest.bin - 1 error(s), 0 warning(s)

This is the exact same error as the one above, if you will notice. Hmm...any ideas?
_________________
http://saoghal.cywh.com/Jer1400/index.html

*Note that the site is still in early development.

#3098 - pollier - Tue Feb 18, 2003 6:24 am

You might want to go into your makefile and remove whatever is inserting "-I C:\GBADEV\CPPTest" into your GCC command line because it seems to be causing trouble and isn't necessary as far as I know. Then again, I don't use DevKitAdvance, so I might be mistaken.

Hope this helps!
_________________
(Works for me!)

#3106 - tubooboo - Tue Feb 18, 2003 10:22 am

why not just get HAM :-) ? (advert alert)

Even if you do not intend to develop using the HAM library, you can just not link that and use the easy IDE and toolchain.

Emanuel
(your advert here)
_________________
HAM author
http://www.ngine.de

#3157 - Jer1400 - Wed Feb 19, 2003 5:40 am

I tried HAM. It took me 3.5 hours to download and then the .zip file was corrupt. It said it was 0 bytes and had no files....
_________________
http://saoghal.cywh.com/Jer1400/index.html

*Note that the site is still in early development.