Meaning of .a extension

G

Giuseppe.G.

Hi what are .a files used for? Are they a kind of archive to hold
libraries? I've installed a toolkit that puts some .h files into /usr/
local/src and a .a file into /usr/local/lib. However, I don't know how
to instruct the compiler to use the contents of the .a file, if it's
really needed and for what.

Cheers
Giuseppe
 
J

James Kanze

.a files in Unix are "archives" of object modules.

Or of anything else. They're files created by the "ar" utility,
and can be used to archive anything. (In the old days, you had
to run ranlib on the output of ar before the linker could use
it. ranlib created an additional index file, and then inserted
it at the start. I think this has pretty much disappeared.)

I've often wondered, in fact, why compilers didn't treat a
request for the library as part of the include path, so that you
could add your headers to the library as well, and thus package
the library as a single file.
They are basically
an equivalent of .lib files on Windows (if you're more familiar with
that environment). A .a file is used by the linker; if the name of the
file you need to add is libXXX.a, you add it to the command line like so:
cc ... -lXXX

That's one way, and it also causes the compiler to look for the
library in a number of specified places (much along the lines of
how it looks for a header file). You can also specify the
pathname directly.
where the letter after the minus is a small L. But all this
is not really a feature of the language, it's a feature of the
OS and your compiler. Please direct your further inquiries to
the newsgroup dedicated to your platform.

I agree that it's platform specific, but I'm not sure I'd call
it a feature:).
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,579
Members
45,053
Latest member
BrodieSola

Latest Threads

Top