C-Static-Library without Makefile ----------------------------------- ===================================== == Step 1.1 : Create a file sum.c ===================================== == .. literalinclude:: static_lib_sum.py ===================================== == ===================================== == Step 1.2 : Create a file sub.c ===================================== == .. literalinclude:: static_lib_sub.py ===================================== == ===================================== == Step 1.3 : Create a file prod.c ===================================== == .. literalinclude:: static_lib_pro.py ===================================== == ====================================== == Step 1.4 : Create a header file math.h ====================================== == .. literalinclude:: static_lib_hdr.py ====================================== == ============================================= == Step 2 : Create a main application file app.c ============================================= == .. literalinclude:: static_lib_app.py ============================================= == ======================================== == Step 3 : Create a static library ======================================== == .. literalinclude:: static_lib_create.py ======================================== == =========================================== =========================================================================================================== Step 4 : Link static library to application Explanation =========================================== =========================================================================================================== .. literalinclude:: static_lib_use.py * -L says “look in directory for library files†* . (the dot after ‘L’) represents the current working directory * -l says “link with this library file†* mathfuns is the name of our library. Note that we omitted the “lib†prefix and “.a†extension. * The linker attaches these parts back to the name of the library to create a name of a file to look for. * -o app says “name the executable file app†=========================================== =========================================================================================================== C-Static-Library with Makefile ---------------------------------------- ================================================ == Step 1.1 : Create a directory structure as below ================================================ == .. literalinclude:: static_lib_make_tree.py ================================================ == ======================================================= == Step 1.2 : Create a file sum.c under library/src folder ======================================================= == .. literalinclude:: static_lib_sum.py ======================================================= == ======================================================= == Step 1.3 : Create a file sub.c under library/src folder ======================================================= == .. literalinclude:: static_lib_sub.py ======================================================= == ======================================================== == Step 1.4 : Create a file prod.c under library/src folder ======================================================== == .. literalinclude:: static_lib_pro.py ======================================================== == =============================================================== == Step 1.5 : Create a header file math.h under library/hdr folder =============================================================== == .. literalinclude:: static_lib_hdr.py =============================================================== == ======================================================================== == Step 1.6 : Create a main application file app.c under library/src folder ======================================================================== == .. literalinclude:: static_lib_app.py ======================================================================== == ====================================================================== == Step 2 : Create a file **Makefile** under library/ folder ====================================================================== == .. literalinclude:: static_lib_makefile.py ====================================================================== == ====================================================================== == Step 3 : Build library and application with make ====================================================================== == .. literalinclude:: static_lib_make_cmd.py ====================================================================== == ====================================================================== == Step 4 : Check that .o, .so and app are copied to obj/ folder ====================================================================== == .. literalinclude:: static_lib_ls_obj.py ====================================================================== == ====================================================================== == Step 5 : Run the program app which is linked to libmathfuns.so ====================================================================== == .. literalinclude:: static_lib_run_app.py ====================================================================== == ====================================================================== == Step 6 : Do clean build ====================================================================== == .. literalinclude:: static_lib_clean_build.py ====================================================================== ==