Originally Posted by
str800
I have a project which builds to several object files (.o) but the thing that confuses me is how to proceed from here if I want to create a single library file?
To make a .a library file:
Code:
ar ruvs libmylibrary.a *.o
To make a .so shared object file:
Code:
ld -shared -o libmylibrary.so *.o
.so and
.ar files, what is the difference between those?
You mean .a, not .ar. A .so is a shared object file which contains relocation information needed by the dynamic linker. All intra-library dependencies are pre-resolved and the code is packaged into a single object. Usually, when compiling code that will become a .so, you should use the -fPIC option of the gcc compiler to generate "position independent code."
A .a is just an archive of .o file (like tar, but not quite) which contains an index of symbol names to accelerate linking against the .o files in the archive. There is no need for -fPIC in this case.