Reputation: 301
I am learning C from a book. The book mentioned archive files:
An archive contains .o files Ever used a .zip or a .tar file? Then you know how easy it is to create a file that contains other files. That’s exactly what a .a archive file is: a file containing other files. Open up a terminal or a command prompt and change into one of the library directories. These are the directories like /usr/lib or C:\MinGW\lib that contain the library code. In a library directory, you’ll find a whole bunch of .a archives. And there’s a command called nm that you can use to look inside them.
However When I looked up the lib location(on Ubuntu) that book says, didn't find archive files. How can I see these archive files?
Upvotes: 0
Views: 3087
Reputation: 112
It depends on the software packages you have installed.
For example, if you install traceroute
, then you should see something like this in /usr/lib/:
# ls -l /usr/lib/*.a
-rw-r--r-- 1 root root 22448 Aug 29 12:45 /usr/lib/libsupp.a
You can easily make your own library. For example:
mylib.c
int hello()
{
return 1;
}
test.c
#include <stdio.h>
int hello();
int main()
{
printf("Hello returned: %d\n", hello());
return 0;
}
Execute:
$ cc -c -o mylib.o mylib.c
$ ar r mylib.a mylib.o
$ cc -o test test.c mylib.a
$ ./test
Hello returned: 1
Upvotes: 1
Reputation: 121417
The location of system libraries could change slightly across different distributions. On Ubuntu, you can find the static libraries in /usr/lib/x86_64-linux-gnu
and /usr/lib32
for 64-bit and 32-bit respectively (This is, in fact, slightly different in older Ubuntu distros. But on recent distros (>Ubuntu 12), this has been consistent).
Upvotes: 2