Penguin
Diff: CompilingHowto
EditPageHistoryDiffInfoLikePages

Differences between version 2 and previous revision of CompilingHowto.

Other diffs: Previous Major Revision, Previous Author, or view the Annotated Edit History

Newer page: version 2 Last edited on Wednesday, September 4, 2002 5:45:20 pm by PerryLorier Revert
Older page: version 1 Last edited on Wednesday, September 4, 2002 5:15:22 pm by PerryLorier Revert
@@ -14,7 +14,25 @@
  
 alternatively 
  gcc foo.c baz.c -o baz 
 will sort the entire thing out for you :) 
+----  
+Object files are .o files. They are fragments of code that may have some unresolved symbols. You link them together with ld(1) which resolves all the symbols from other .o files or from libraries.  
+  
+.a files are libraries of .o files. They are kinda like a .zip file for .o files. ar(1) is the tool to manage .a files. if you run ranlib(1) over a .a file it will create an index of all the symbols making your compiles faster. I believe [GNU] ar(1) keeps the symbol table up to date so ranlib(1) isn't required, but I could be wrong.  
+  
+libtool(1) is a program to manage libraries in a CrossPlatform manner under Unix.  
+  
+Instead of making an executable, you can make a shared library by compiling with the flags "-shared" (this is a shared library), and -fPIC (create PositionIndependantCode). the -fPIC is optional, if you don't use it then when the library is loaded into memory ld.so(8) will relocate the symbols for you (See RelocatingSymbols) which will write to the memory used by the library, and thusly will cause that library not to be shared between processes due to CopyOnWrite. I don't know why you wouldn't want to use -fPIC if your platform supports it, so use it :)  
+ gcc foo.c -shared -fPIC -c -o foo.o  
+You can open dynamically loaded modules using dlopen(3). You can probably link against these, although I've never bothered figuring out how.  
+  
+If you want to make a library that is statically compiled into a program then compile it into a .a file called lib''thenameofyourlibrary''.a and put it in some directory. Then when compiling your main program use -L/path/to/the/libraries to make the compiler search that directory and put -l''thenameofyourlibrary'' on the command line. eg:  
+ gcc foo.c -c -o foo.o  
+ ar rcs libs/libfoo.a foo.o  
+ ranlib libs/libfoo.a  
+ gcc baz.c -Llibs/ -lfoo -o baz  
+  
+a.out is the default name given to a program if none was specified with the -o command line option. The reason for this is that it used to be the assembler output (Before seperate linking was used), thus a (the assembler) .out (output).  
  
 ---- 
 SeeAlso MakefileHowto