Dark Bit Factory & Gravity

PROGRAMMING => Freebasic => Topic started by: Clyde on February 20, 2009

Title: An .a file?
Post by: Clyde on February 20, 2009
Just out of curiosity with all these specially designed wrappers and libs, I wondered what exactly an .a file is?

How do you make one, what tools do you need etc?

Thanks for the info,
Clyde.
Title: Re: An .a file?
Post by: Jim on February 20, 2009
It's called a static library.

Effectively it's a library of code.  It usually exposes a number of functions, which can be called if you link the .a with your program.
In C and C++, you'll need an .h file to do that, in FB you'll need a .bi file, etc.

On Windows, .a files are normally Win32 .lib files that have been renamed to work with Linux tools that have been ported to Windows, like DevC and FBIDE.

Jim
Title: Re: An .a file?
Post by: Clyde on February 20, 2009
Cool, thanks Jim.

Can the code be of any language and is there a means to have a look inside such a file?
Is a .dll pretty much similiar, I wouldnt mind looking inside those too.
Title: Re: An .a file?
Post by: Jim on February 20, 2009
.a/.lib are static files.  When compile an exe you attach them to the exe they become part of it.  With .dll (or the Linux equivalent .so) files, the exe links to them at run time (hence the name Dynamic Link Library), so you save a lot of space.
Inside them is just binary code, you'd need a disassembler to look at them.  There's no source code in there.

Jim
Title: Re: An .a file?
Post by: Clyde on February 21, 2009
I presume that initially these can be coded in any language besides assembler, and get processed into their form when you make one properly; with whatever tool it is you use. As I remember seeing some dlls ( no luck with A files mind ) that I looked at in notepad, and at what looked like C or a variant of it. btw, can these be re-assembled into their original form?

Cheers,
Doctor Watson.
Title: Re: An .a file?
Post by: Jim on February 22, 2009
You can use pretty much any compiler+linker to make a dll/lib using pretty much any compiled language.  They're just like exe files with a different header.

When you open them in notepad, what you are seeing are the symbols that are used to perform the linking.
For example, my exe might want a function called "CreateWindow", and the dll will have an entry in it identified by the text "CreateWindow" followed by a pointer to the code inside the dll.
Just like with an exe there's no way to get back the original source code.

The big advantage of dlls over lib files which I forgot to mention is that there is only ever one copy of a dll loaded and all exes that require the functions share the same dll.
That saves on memory and disk space when you have lots of programs.

Jim