Showing posts with label c++. Show all posts
Showing posts with label c++. Show all posts

Tuesday, March 22, 2011

GCC stuff

I've often had to build some programs from source have been a little confused as to what shared libraries, static libraries, .a files, and .so files are, and how they relate to the -I -L -l options for GCC. A wonderful website that cleared all this up for me is http://www.network-theory.co.uk/docs/gccintro/index.html, here are some notes I've just scrapped down for my own reference

What is a Library
A library is
  • Useful code that has been compiled already 
  • Hence saves having to recompile that same bit of code
  • Can be used (linked to) in other programs or by other people
  • DRY (don't repeat yourself) principles - don't need to reinvent the wheel for universal functions. Eg you don't want to have to program how to draw a window with the maximize, minimize, close buttons for every program you make, so instead you can link to the windows libraries.
Static vs. Shared (Dynamic)
Static Library
  • Stored in archive .a files
  • Machine code for external functions is copied directly to your final executable
  • Makes your executable larger
  • (makes it easier to give to friends, they don't need library installed?)
Shared Library
  • Stored as shared object .so files 
  • Only a table of functions used is stored in your exe
  • when your exe starts, it loads up the linked libraries into memory (dynamic linking)
  • Final exe is smaller
  • OS will load the linked library into virtual memory, this can be used by multiple programs at once - saving memory usage
  • Can update library without recompiling code (unless the APIs change)

LinkWithin

Related Posts with Thumbnails