Penguin
Diff: SharedLibraryNotes
EditPageHistoryDiffInfoLikePages

Differences between version 4 and revision by previous author of SharedLibraryNotes.

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

Newer page: version 4 Last edited on Wednesday, February 23, 2005 2:31:24 pm by SamJansen Revert
Older page: version 1 Last edited on Thursday, November 11, 2004 4:27:03 am by AristotlePagaltzis Revert
@@ -40,8 +40,41 @@
  
 So long as you don't change the call signature of one of the functions (or what they do, in a way that would break programs), you can just bump the minor version of the library and programs using the SharedLibrary will just work. If you do change call signatures on existing functions or change their semantics, bump the version, try to recompile the programs, and check that they work correctly once they pass. Another way to make it usable is to put it in a directory refered to in your <tt>LD_LIBRARY_PATH</tt> EnvironmentVariable. 
  
 You may wish to use <tt>-Wl,-O1</tt> when linking too, it will optimise the hashtables used for symbol lookup making the startup time faster. 
+  
+!!! Creating static shared libraries  
+  
+In some cases you may not want your shared library to have any extra dependencies. In such a case you want your shared library to have its dependencies statically linked in. Even a simple shared library will have a couple of dependences:  
+  
+<verbatim>  
+ldd ./libsam.so  
+ libc.so.6 => /lib/libc.so.6 (0x0000002a95675000)  
+ /lib64/ld-linux-x86-64.so.2 (0x000000552aaaa000)  
+</verbatim>  
+  
+The obvious way to statically link these dependencies would be:  
+  
+<verbatim>  
+gcc -shared -static -o libsam.so sam.c  
+</verbatim>  
+  
+This will either not work, or give an error message like:  
+  
+<verbatim>  
+gcc: -shared and -static|pie|fPIE|fpie|fno-PIC|fno-pic|nopie are incompatible  
+</verbatim>  
+  
+However, it is possible to directly tell the linker we want static linking, and then magic will happen:  
+  
+<verbatim>  
+gcc -shared -Wl,-static -o libsam.so sam.c  
+  
+ldd ./libsam.so  
+ statically linked  
+</verbatim>  
+  
+''libsam.so'' is still a valid shared library, it just lacks any external dependency. In some cases you might need the command-line option ''-static-libgcc'' for this to work.  
  
 !!! Creating a SharedLibrary using libtool(1) 
  
 libtool(1) is a package designed to assist with the creation of shared libraries. See the libtool(1) node for more information (eventually) about this program