Warning: Undefined array key 1 in /home/yogindar/www/blog/wp-content/plugins/visitors-online/visitors-online.php on line 505

Warning: Undefined array key 2 in /home/yogindar/www/blog/wp-content/plugins/visitors-online/visitors-online.php on line 505

Warning: Cannot modify header information - headers already sent by (output started at /home/yogindar/www/blog/wp-content/plugins/visitors-online/visitors-online.php:505) in /home/yogindar/www/blog/wp-content/plugins/visitors-online/visitors-online.php on line 557

Warning: Cannot modify header information - headers already sent by (output started at /home/yogindar/www/blog/wp-content/plugins/visitors-online/visitors-online.php:505) in /home/yogindar/www/blog/wp-includes/rest-api/class-wp-rest-server.php on line 1930

Warning: Cannot modify header information - headers already sent by (output started at /home/yogindar/www/blog/wp-content/plugins/visitors-online/visitors-online.php:505) in /home/yogindar/www/blog/wp-includes/rest-api/class-wp-rest-server.php on line 1930

Warning: Cannot modify header information - headers already sent by (output started at /home/yogindar/www/blog/wp-content/plugins/visitors-online/visitors-online.php:505) in /home/yogindar/www/blog/wp-includes/rest-api/class-wp-rest-server.php on line 1930

Warning: Cannot modify header information - headers already sent by (output started at /home/yogindar/www/blog/wp-content/plugins/visitors-online/visitors-online.php:505) in /home/yogindar/www/blog/wp-includes/rest-api/class-wp-rest-server.php on line 1930

Warning: Cannot modify header information - headers already sent by (output started at /home/yogindar/www/blog/wp-content/plugins/visitors-online/visitors-online.php:505) in /home/yogindar/www/blog/wp-includes/rest-api/class-wp-rest-server.php on line 1930

Warning: Cannot modify header information - headers already sent by (output started at /home/yogindar/www/blog/wp-content/plugins/visitors-online/visitors-online.php:505) in /home/yogindar/www/blog/wp-includes/rest-api/class-wp-rest-server.php on line 1930

Warning: Cannot modify header information - headers already sent by (output started at /home/yogindar/www/blog/wp-content/plugins/visitors-online/visitors-online.php:505) in /home/yogindar/www/blog/wp-includes/rest-api/class-wp-rest-server.php on line 1930

Warning: Cannot modify header information - headers already sent by (output started at /home/yogindar/www/blog/wp-content/plugins/visitors-online/visitors-online.php:505) in /home/yogindar/www/blog/wp-includes/rest-api/class-wp-rest-server.php on line 1930
{"id":2171,"date":"2020-08-28T17:14:42","date_gmt":"2020-08-28T17:14:42","guid":{"rendered":"http:\/\/www.yogindar.com\/news\/?p=2171"},"modified":"2020-08-30T07:26:37","modified_gmt":"2020-08-30T07:26:37","slug":"working-with-shared-libraries-set-1-geeksforgeeks","status":"publish","type":"post","link":"http:\/\/blog.yogindar.org\/?p=2171","title":{"rendered":"Quick summary on shared libraries"},"content":{"rendered":"

Shared libraries are reusable libraries which can be used by multiple applications at the same time. The advantages of shared libraries are<\/p>\n

    \n
  1. Can be loaded at application start or on demand at run time.<\/li>\n
  2. Can be upgraded separately and reloaded.<\/li>\n<\/ol>\n

    Only disadvantage compared to statically linked library is, there is an overhead for loading the library and resolving the symbols at run time.<\/p>\n

    In case of loading during application start, the loader will load the library into process virtual address space and resolve before the application is launched.<\/p>\n

    In case of loading dynamically the same can be achieved with the respective system library apis when in need..<\/p>\n

    Windows it will be a dynamically linked library(*.dll) and uses the same PE format as windows executable.<\/p>\n

    Linux it will be a shared object(*.so) and uses the ELF format as a normal linux executable.<\/p>\n

    In linux use the -shared gcc option to create a shared object. if your library name provided is abc.so, the linux linker will create it as libabc.so.<\/p>\n

    While statically linking, the option -labc should be provided to link with the same.<\/p>\n

    If you are using dynamic linking, you need to use dlopen(3) ,dlsym(3) and dlclose(3) apis to load, access the symbol and unload the library.<\/p>\n

    Sample codes<\/p>\n

    application.c<\/p>\n

    #include <stdio.h>
    \n#include “call_lib.h”<\/p>\n

    int main(int argc, char * argv[])
    \n{
    \nprintf(“In application\\n”);
    \ncall_lib(3);<\/p>\n

    return 0;
    \n}<\/p>\n

    call_lib.h<\/p>\n

    int call_lib(int num);<\/p>\n

    library.c<\/p>\n

    #include <stdio.h>
    \n#include “call_lib.h”<\/p>\n

    int call_lib(int num)
    \n{
    \nprintf(“passed value is %d\\n”, num);<\/p>\n

    return 0;
    \n}<\/p>\n

    To compile the library code
    \ngcc -shared -fPIC -o library.so library.c<\/p>\n

    To compile the application code
    \ngcc -o sample -L \/home\/yogi\/libs -lrary application.c<\/p>\n

    Running the executable<\/p>\n

    set first the library path<\/p>\n

    $export LD_LIBRARY_PATH=\/home\/yogi\/libs:$LD_LIBRARY_PATH
    \n$ .\/sample
    \nIn application
    \npassed value is 3<\/p><\/blockquote>\n

    Source: Working with Shared Libraries | Set 1 – GeeksforGeeks<\/a><\/em><\/p>\n","protected":false},"excerpt":{"rendered":"

    Shared libraries are reusable libraries which can be used by multiple applications at the same time. The advantages of shared libraries are Can be loaded at application start or on demand at run time. Can be upgraded separately and reloaded. Only disadvantage compared to statically linked library is, there is an overhead for loading the […]<\/p>\n","protected":false},"author":29,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1337,310],"tags":[1563,1333,1562],"class_list":["post-2171","post","type-post","status-publish","format-standard","hentry","category-my-article","category-programming","tag-dynamic-linking","tag-programming-2","tag-shared-object"],"_links":{"self":[{"href":"http:\/\/blog.yogindar.org\/index.php?rest_route=\/wp\/v2\/posts\/2171","targetHints":{"allow":["GET"]}}],"collection":[{"href":"http:\/\/blog.yogindar.org\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/blog.yogindar.org\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/blog.yogindar.org\/index.php?rest_route=\/wp\/v2\/users\/29"}],"replies":[{"embeddable":true,"href":"http:\/\/blog.yogindar.org\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=2171"}],"version-history":[{"count":5,"href":"http:\/\/blog.yogindar.org\/index.php?rest_route=\/wp\/v2\/posts\/2171\/revisions"}],"predecessor-version":[{"id":2185,"href":"http:\/\/blog.yogindar.org\/index.php?rest_route=\/wp\/v2\/posts\/2171\/revisions\/2185"}],"wp:attachment":[{"href":"http:\/\/blog.yogindar.org\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=2171"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/blog.yogindar.org\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=2171"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/blog.yogindar.org\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=2171"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}