475

I'm currently trying to port a C application to AIX and am getting confused. What are .a and .so files and how are they used when building/running an application?

Peter Mortensen
  • 28,342
  • 21
  • 95
  • 123
Dunc
  • 6,777
  • 9
  • 27
  • 35

5 Answers5

535

Archive libraries (.a) are statically linked i.e when you compile your program with -c option in gcc. So, if there's any change in library, you need to compile and build your code again.

The advantage of .so (shared object) over .a library is that they are linked during the runtime i.e. after creation of your .o file -o option in gcc. So, if there's any change in .so file, you don't need to recompile your main program. But make sure that your main program is linked to the new .so file with ln command.

This will help you to build the .so files. http://www.yolinux.com/TUTORIALS/LibraryArchives-StaticAndDynamic.html

Hope this helps.

Leafy
  • 5,771
  • 1
  • 13
  • 13
240

.a are static libraries. If you use code stored inside them, it's taken from them and embedded into your own binary. In Visual Studio, these would be .lib files.

.so are dynamic libraries. If you use code stored inside them, it's not taken and embedded into your own binary. Instead it's just referenced, so the binary will depend on them and the code from the so file is added/loaded at runtime. In Visual Studio/Windows these would be .dll files (with small .lib files containing linking information).

Mario
  • 33,344
  • 5
  • 53
  • 74
13

.a files are usually libraries which get statically linked (or more accurately archives), and
.so are dynamically linked libraries.

To do a port you will need the source code that was compiled to make them, or equivalent files on your AIX machine.

gbulmer
  • 3,933
  • 14
  • 19
  • How do I build my application to use .so files? – Dunc Mar 21 '12 at 16:58
  • There are many excellent references for building both types of libraries and linking to them on the web. Google is your friend. – David Pointer Mar 21 '12 at 17:06
  • @Dunc - There are a couple of ways. Do you have a makefile? Usually the command that assembles the whole program (and hence calls the linker) will specify the places to look for library files with -L/dir/dir1/.../ and may also name libraries explicitly with -lname. You will find that the actual name is libname.a or libname.so. The linker can then figure out what to do if this is a reasonably normal program. But you still have the problem of making or finding the .so file. Have you got source code to build it, or an AIX library? – gbulmer Mar 21 '12 at 17:08
11

They are used in the linking stage. .a files are statically linked, and .so files are sort-of linked, so that the library is needed whenever you run the exe.

You can find where they are stored by looking at any of the lib directories... /usr/lib and /lib have most of them, and there is also the LIBRARY_PATH environment variable.

Matt
  • 6,892
  • 2
  • 26
  • 53
2

Wikipedia is a decent source for this info.

To learn about static library files like .a read Static libarary

To learn about shared library files like .so read Library_(computing)#Shared_libraries On this page, there is also useful info in the File naming section.

user3731622
  • 3,753
  • 2
  • 31
  • 64