CEG 221 Lesson 6 Using Building Libraries Mr

CEG 221 Lesson 6: Using & Building Libraries Mr. David Lippa

Overview • Building Libraries – What are libraries? – Why build libraries? – How to build libraries • Using Libraries • Tradeoffs • Questions

What are libraries? • A library is a collection of data structures and functions that are grouped together by relevance with a specific purpose in mind – Precompiled library – a header file containing function prototypes and a. LIB file consisting of their function bodies; the header file is said to be the interface • kernel 32. lib is a precompiled library of routines and structures used to make an application run under 32 -bit Windows™ – Uncompiled library – a library consisting of header files (. h) and C source files (. c) • stdio. h is an uncompiled library of structures (FILE*) and functions (printf, scanf, etc. ) for user input/output

Why Build Libraries? • They add an extra layer to modular programming – a module that is a collection of modules • They are portable (cross-platform) when distributed as source files and let you build them on whatever platform (OS) is needed with whatever compiler • They hide the headers/interface (how to use) from the source/implementation (the actual work)

Precompiled Libraries • Precompiled libraries come with a. LIB file and header files that specify how to use the library • They are platform-specific – it must be properly compiled on the same processor type (ie. x 86), OS, and compiler • They need to be linked with your application, and their header files must be included in the project

Uncompiled Libraries • Uncompiled libraries come with complete source code • Consists of header files (. h) which consist of data structures and function prototypes (interface) and source files (. c) which consist of function bodies (implementation) • They either need to be – compiled into a. LIB file and then linked – included in the project with the rest of your source files

Examples • Libraries of Libraries: Red Hat Linux – an OS that has libraries and header files built into the operating system to build the next version of that operating systemx • JPG, HDF Libraries for importing images • Windowing Toolkits (QT, MFC) for building Graphical User Interfaces and applications • Groupware Toolkits for building Groupware/collaboration applications • Precompiled Library Demo: Integration

Advantages and Disadvantages Precompiled: • PROS: Just link, add header files, and run! • CONS: Compiler, Processor, and OSspecific Uncompiled: • PROS: crossplatform, easier to debug • CONS: more difficult to use; difficult to debug if it fails to compile • When looking for a library, it is typically best to get a precompiled library for a novice user • Both types typically come with documentation on how to use the library and what each function does

Questions?
- Slides: 9