| Main |
|
BUILDING STATIC LIBRARY (EXAMPLE) In this example static library contains two definitions of classes, which are compiled separately:
1. Compiling two classes (creating static modules): >g++ -c class1.cpp -o class1.o >g++ -c class2.cpp -o class2.o 2. Building static library: >ar -rcs libStaticLibExample.a class1.o class2.o 3. Using classes from library in program:
4. Compiling program.cpp: >g++ -c program.cpp -o program.o 5. Linking program with static library (if library is in the same folder): >g++ program.o libStaticLibExample.a -o program.exe or (if library is in default lib folder): >g++ program.o -lStaticLibExample -o program.exe Note that linker links only modules (not whole library), in this example class1.o and class2.o from library, which contains compiled code of classes used in program. |