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.

Beginners > .a files?

#170798 - atenzor - Wed Oct 21, 2009 2:57 am

Hi, I saw lot of library files with .a files? How to open/edit them?
What are they?

Thanks!

#170799 - Dwedit - Wed Oct 21, 2009 3:00 am

They're basically collections of .o files. You usually don't look at them yourself, usually just letting the compiler link them with your binary for you. But with the right combination of tools, you could split them to object files, and disassemble the object files with symbols.
_________________
"We are merely sprites that dance at the beck and call of our button pressing overlord."

#170801 - atenzor - Wed Oct 21, 2009 5:13 am

can you tell me what tools to use to manipulate these files. i want to learn. thanks

#170805 - Kyoufu Kawa - Wed Oct 21, 2009 12:53 pm

Stuff like ar, short for archive, I'd guess.

#170807 - Dwedit - Wed Oct 21, 2009 1:25 pm

You could either manipulate the .a files, or just grab the source code.

But anyway yeah...

"arm-eabi-ar x libgba.a" will extract all the .o files out of libgba.
"arm-eabi-objdump -d console.o > console.s" will show you the disassembly of console.o. And of course, the original source code is available from DevKitPro SVN.


Other useful tricks include looking at the MAP file created in the Build directory, and seeing which library code was brought in. If your executables get really bloated with library code which is never called (such as __eabi_atexit or something like that), you can create blank functions to stop the extra library code from being brought in.
_________________
"We are merely sprites that dance at the beck and call of our button pressing overlord."

#170811 - ritz - Wed Oct 21, 2009 3:01 pm

Dwedit wrote:
you can create blank functions to stop the extra library code from being brought in

This is interesting. How would I go about doing this? Just a blank function with the exact same name? I've always hated the extra big stuff that gets put in that I don't use.

I'd try figuring it out myself first, but I left my flash drive at home (my code and tool chain are on it).

#170817 - Miked0801 - Wed Oct 21, 2009 4:26 pm

The linker is pretty good and dead stripping unused functions. If you find a function in your map file that is unexpected, it's a better idea to trace why that function is there than to overload its symbol away and pray that your game doesn't crash in new and exciting ways. Floating Point is a good example for me. When I find large amounts of floating point code suddenly appearing, I know that someone accidently dropped a decimal point into a number somewhere incorrectly and that it needs to be found before other bugs build off it.

#170821 - atenzor - Wed Oct 21, 2009 5:58 pm

OK thanks guys, I will try and see what I can do. thanks again! :)

#170829 - atenzor - Wed Oct 21, 2009 10:32 pm

OK, I have extracted the .a files and got bunch of .o files. I assume those are object files. Is there a way to extract those? If so, how/what tool?

Also, how does someone compile a bunch of .o files into a .a file? Is it with command "arm-eabi-ar.exe -r libname.a file1.o file2.o file3.o"?

Thanks!

#170830 - kusma - Wed Oct 21, 2009 10:43 pm

atenzor wrote:
I assume those are object files. Is there a way to extract those? If so, how/what tool?

Do you mean disassemble them? In that case you can use objdump, a tool that comes with devkitARM.

#170832 - atenzor - Wed Oct 21, 2009 10:59 pm

Yes, I was able to disassemble them, but how does someone create .o (object files) anyway? I think I saw something like "gcc file.c -o file.o", is that the way? thanks.

#170834 - Drovor - Thu Oct 22, 2009 1:25 am

yes

#170844 - atenzor - Thu Oct 22, 2009 6:43 pm

OK, so how is a library created? Like it all starts with some files (.h, .c, etc) and some other files and then they are converted to .o (object files).
Finally, all object files are grouped into an archive file (.a)? Is that it? Or is there other ways to create a library?

Also, how is the .a file used with homebrew development, I mean what do you do with the library, how do you use it`s elements to help you?

Thanks!

#170846 - kusma - Thu Oct 22, 2009 9:03 pm

atenzor wrote:
OK, so how is a library created? Like it all starts with some files (.h, .c, etc) and some other files and then they are converted to .o (object files).
Finally, all object files are grouped into an archive file (.a)? Is that it? Or is there other ways to create a library?

You are pretty much right. Source files are compiled into object files, which are archived together as a library. Typically something like this:
Code:
$ cc -c file1.c -o file1.o
$ cc -c file2.c -o file2.o
$ ar -r libfoo.a file1.o file2.o


Quote:

Also, how is the .a file used with homebrew development, I mean what do you do with the library, how do you use it`s elements to help you?

When you have a library, you can call functions from it if your application links to it. You link to it by passing the archive filename to the linker, just like you do with an object file. Typically somethig like this:
Code:
$ cc -c myapp.c -o myapp.o
$ ld myapp.o libfoo.a -o myapp.elf

#170847 - atenzor - Thu Oct 22, 2009 9:09 pm

Hmm, OK, thanks.

#171138 - Azenris - Mon Nov 02, 2009 10:47 pm

Hi, how exactly do I add a library, I changed my arm9 makefile but get the error

Code:
cannot find -myLib


I changed

Code:
LIBS   := -lfat -lnds9


to

Code:
LIBS   := -myLib -lfat -lnds9


and

Code:
LIBDIRS   :=   $(LIBNDS)


to

Code:
LIBDIRS   :=   $(LIBNDS) data/lib


Im guessing thats wrong as it wont work :( The folder is with the makefile and goes

Code:
data/lib/myLib.a
data/lib/include/includefileshere.h

_________________
My Homebrew Games

#171139 - vuurrobin - Mon Nov 02, 2009 10:51 pm

you need to change the -myLib to -lmyLib (the -l part tells gcc that you want to add a library) and your myLib.a into libmyLib.a.
_________________
my blog:
http://vuurrobin.100webcustomers.com/

#171140 - Azenris - Mon Nov 02, 2009 11:01 pm

ill say foo instead of myLib since that has lib in the name

I tried
Code:

LIBS   := -lfoo -lfat -lnds9
LIBDIRS   :=   $(LIBNDS) data/lib

and
Code:

LIBS   := -llibfoo -lfat -lnds9
LIBDIRS   :=   $(LIBNDS) data/lib


both with and without renaming the actual file libfoo.a
_________________
My Homebrew Games

#171141 - Dwedit - Mon Nov 02, 2009 11:12 pm

You're not mixing C and C++ symbols by any chance, are you?
_________________
"We are merely sprites that dance at the beck and call of our button pressing overlord."

#171142 - Azenris - Mon Nov 02, 2009 11:15 pm

I've written everything in C++ :/

EDIT:
The problem must be with my directory setting, should it just be data/lib or should more be there.

The library links fine if I just shove it in devkitPro/libnds/lib
_________________
My Homebrew Games

#171153 - vuurrobin - Tue Nov 03, 2009 9:39 am

the libdir should point to the directory with the lib and include directory, so just data in this case, not data/lib.


also, I'm not sure where the data directory is, but you may want to add that to. for DSOL I use $(DEVKITPRO)/DSOL.
_________________
my blog:
http://vuurrobin.100webcustomers.com/

#171156 - Dwedit - Tue Nov 03, 2009 4:43 pm

Maybe it's the revenge of the base directory being "build" instead of ".". Maybe you need a ../ before data/lib
_________________
"We are merely sprites that dance at the beck and call of our button pressing overlord."

#171205 - doatkiem - Fri Nov 06, 2009 7:09 am

Some one can tell me which is better? VisualHAM or Devkitpro?

#171209 - kusma - Fri Nov 06, 2009 11:19 am

doatkiem wrote:
Some one can tell me which is better? VisualHAM or Devkitpro?

Depends on what you mean by "better". I prefer devkitPro, as it's software is much more up to date, and the libraries that comes with it is much more to my liking... But VisualHAM is a more complete IDE than what Programmers Notepad (the editor bundled with devkitPro) is.

#171214 - doatkiem - Fri Nov 06, 2009 3:50 pm

thanks a lot kusma!!

#171216 - vuurrobin - Fri Nov 06, 2009 11:34 pm

kusma wrote:
doatkiem wrote:
Some one can tell me which is better? VisualHAM or Devkitpro?

Depends on what you mean by "better". I prefer devkitPro, as it's software is much more up to date, and the libraries that comes with it is much more to my liking... But VisualHAM is a more complete IDE than what Programmers Notepad (the editor bundled with devkitPro) is.


I think that most people will just say that devkitPro is better.

as for IDE, you don't need to use programmers notepad when using devkitPro. you could use MS visual studio or codeblocks or alot of other IDEs.
_________________
my blog:
http://vuurrobin.100webcustomers.com/