{"id":300944,"date":"2021-07-16T14:30:09","date_gmt":"2021-07-16T11:30:09","guid":{"rendered":"https:\/\/en.buradabiliyorum.com\/how-to-work-with-shared-object-library-dependencies-in-linux-cloudsavvy-it\/"},"modified":"2021-07-16T14:30:09","modified_gmt":"2021-07-16T11:30:09","slug":"how-to-work-with-shared-object-library-dependencies-in-linux-cloudsavvy-it","status":"publish","type":"post","link":"https:\/\/buradabiliyorum.com\/en\/how-to-work-with-shared-object-library-dependencies-in-linux-cloudsavvy-it\/","title":{"rendered":"#How to Work with Shared Object (Library) Dependencies in Linux \u2013 CloudSavvy IT"},"content":{"rendered":"<div id=\"ez-toc-container\" class=\"ez-toc-v2_0_84 counter-hierarchy ez-toc-counter ez-toc-custom ez-toc-container-direction\">\n<p class=\"ez-toc-title\" style=\"cursor:inherit\">Table of Contents<\/p>\n<label for=\"ez-toc-cssicon-toggle-item-6a259a0f270df\" class=\"ez-toc-cssicon-toggle-label\"><span class=\"\"><span class=\"eztoc-hide\" style=\"display:none;\">Toggle<\/span><span class=\"ez-toc-icon-toggle-span\"><svg style=\"fill: #dd3333;color:#dd3333\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\" class=\"list-377408\" width=\"20px\" height=\"20px\" viewBox=\"0 0 24 24\" fill=\"none\"><path d=\"M6 6H4v2h2V6zm14 0H8v2h12V6zM4 11h2v2H4v-2zm16 0H8v2h12v-2zM4 16h2v2H4v-2zm16 0H8v2h12v-2z\" fill=\"currentColor\"><\/path><\/svg><svg style=\"fill: #dd3333;color:#dd3333\" class=\"arrow-unsorted-368013\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"10px\" height=\"10px\" viewBox=\"0 0 24 24\" version=\"1.2\" baseProfile=\"tiny\"><path d=\"M18.2 9.3l-6.2-6.3-6.2 6.3c-.2.2-.3.4-.3.7s.1.5.3.7c.2.2.4.3.7.3h11c.3 0 .5-.1.7-.3.2-.2.3-.5.3-.7s-.1-.5-.3-.7zM5.8 14.7l6.2 6.3 6.2-6.3c.2-.2.3-.5.3-.7s-.1-.5-.3-.7c-.2-.2-.4-.3-.7-.3h-11c-.3 0-.5.1-.7.3-.2.2-.3.5-.3.7s.1.5.3.7z\"\/><\/svg><\/span><\/span><\/label><input type=\"checkbox\"  id=\"ez-toc-cssicon-toggle-item-6a259a0f270df\" checked aria-label=\"Toggle\" \/><nav><ul class='ez-toc-list ez-toc-list-level-1 ' ><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-1\" href=\"https:\/\/buradabiliyorum.com\/en\/how-to-work-with-shared-object-library-dependencies-in-linux-cloudsavvy-it\/#What_Is_a_Shared_Object_Dependency\" >What Is a Shared Object Dependency?<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-2\" href=\"https:\/\/buradabiliyorum.com\/en\/how-to-work-with-shared-object-library-dependencies-in-linux-cloudsavvy-it\/#Error_while_Loading_Shared_Libraries\" >Error while Loading Shared Libraries!<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-3\" href=\"https:\/\/buradabiliyorum.com\/en\/how-to-work-with-shared-object-library-dependencies-in-linux-cloudsavvy-it\/#Wrapping_Up\" >Wrapping Up<\/a><\/li><\/ul><\/nav><\/div>\n<p><strong>&#8220;#How to Work with Shared Object (Library) Dependencies in Linux \u2013 CloudSavvy IT&#8221;<\/strong><\/p>\n<div id=\"article-content-area\">\n<figure style=\"width: 3496px\" class=\"wp-caption alignnone\"><img loading=\"lazy\" decoding=\"async\" class=\"type:primaryImage wp-image-12685 size-full\" srcset=\"https:\/\/www.cloudsavvyit.com\/p\/uploads\/2021\/06\/9a3f0be2.png?width=398&amp;trim=1,1&amp;bg-color=000&amp;pad=1,1 400w, https:\/\/www.cloudsavvyit.com\/p\/uploads\/2021\/06\/9a3f0be2.png?width=1198&amp;trim=1,1&amp;bg-color=000&amp;pad=1,1 1200w\" sizes=\"auto, 400w, 1200w\" src=\"https:\/\/www.cloudsavvyit.com\/p\/uploads\/2021\/06\/9a3f0be2.png?width=398&amp;trim=1,1&amp;bg-color=000&amp;pad=1,1\" alt=\"library text on white background\" width=\"3496\" height=\"1810\" data-crediturl=\"https:\/\/www.shutterstock.com\/image-vector\/vector-library-online-pattern-seamless-background-1130054744\" data-credittext=\"Dima Polies\/Shutterstock.com\" onload=\"pagespeed.lazyLoadImages.loadIfVisibleAndMaybeBeacon(this);\" onerror=\"this.onerror=null;pagespeed.lazyLoadImages.loadIfVisibleAndMaybeBeacon(this);\"\/><figcaption class=\"wp-caption-text\"><span class=\"type:primaryImage imagecredit\"><a rel=\"nofollow noopener\" target=\"_blank\" href=\"https:\/\/www.shutterstock.com\/image-vector\/vector-library-online-pattern-seamless-background-1130054744\">Dima Polies\/Shutterstock.com<\/a><\/span><\/figcaption><\/figure>\n<p>Error while loading shared libraries: the dreaded error that every Linux user will sooner or later run into. Something went wrong with the shared object dependencies (the libraries) used by the executable. Learn how to fix such issues and more!<\/p>\n<h2 role=\"heading\" aria-level=\"2\"><span class=\"ez-toc-section\" id=\"What_Is_a_Shared_Object_Dependency\"><\/span>What Is a <i>Shared Object Dependency<\/i>?<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p>A shared object (also called a library) is a binary (usually not directly executable) used by multiple programs\/<a href=\"https:\/\/buradabiliyorum.com\/en\/category\/download-scripts-themes-apps\/\" data-internallinksmanager029f6b8e52c=\"9\" title=\"Download Scripts &amp; Themes &amp; Apps\" target=\"_blank\" rel=\"noopener\">app<\/a>lications on a Linux instance. Such libraries are often installed at the operating system level and are shared (hence the name <i>shared object<\/i> or <code>libraries<\/code>) for use by one or more (and even many) directly executable applications.<\/p>\n<p>For example, a program that features compressing files might require the bz2 (bzip2) library <code>libbz2.so.1.0<\/code> to do so. The term <i>library<\/i> is more often used in Linux circles and is the preferred lingo among professionals, although <i>shared object<\/i> (and <i>shared library<\/i>) are both technically correct. Also interesting to note is that the <code>.so<\/code> file name extension used in many libraries stands for <i>shared object<\/i>!<\/p>\n<p>An executable can have zero, one, or many libraries that it relies on. The fewer libraries, the more forward (when upgrading your operating system, for example) the compatibility will be. The more libraries, the greater the chance that sooner or later, some library dependency will break. This is also why application vendors sometimes decide to release <code>statically compiled binaries<\/code> rather than <code>dynamically compiled binaries<\/code>.<\/p>\n<p>The difference between statically and dynamically compiled binaries is simple but has far-reaching consequences. A statically compiled binary has the libraries (available on the developer system at the time of compiling) compiled into the resulting binary\/executable. A dynamically compiled binary will use the libraries installed, available, and shared on the user\u2019s system.<\/p>\n<p>As you can im<a href=\"https:\/\/buradabiliyorum.com\/en\/category\/social-mediaa\/\" data-internallinksmanager029f6b8e52c=\"1\" title=\"Social Media\" target=\"_blank\" rel=\"noopener\">media<\/a>tely see, this would require the user to install any such required dependencies, unless the same is taken care of in the operating system or application vendor\u2019s package management system and details. This is why running a simple command like <code>sudo apt install ...some_app...<\/code> will often yield a set of other related things (i.e. required libraries) to be co-installed at the same time.<\/p>\n<p>Both static and dynamic compiling have pros and cons. For example, if you use static compiling, and a library that you\u2019ve included in your software package (from the perspective of a software vendor) now has a security bug or critical update, it will likely mean that you have to re-release your software package, even if nothing has changed in your code.<\/p>\n<p>But then again, relying on the user to install libraries, especially for complex programs, or when self-compilation of software is required, with the realization that end-users often struggle with such things, isn\u2019t ideal either. It\u2019s a complex area, and the issue has been discussed often.<\/p>\n<p>For the purposes of this article, we will look at shared libraries in connection with a program that was dynamically compiled, as is often the case with operating system programs\/executables\/tools. With statically compiled programs (which are less common), an error like \u2018Error while loading shared libraries\u2019 is highly unlikely to display, as the libraries are included in the executable unless the program is part dynamic and only includes a limited set of built-in static libraries.<\/p>\n<h2 role=\"heading\" aria-level=\"2\"><span class=\"ez-toc-section\" id=\"Error_while_Loading_Shared_Libraries\"><\/span>Error while Loading Shared Libraries!<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p>Let\u2019s switch into <i>root<\/i> mode for a while (using <code>sudo su<\/code>) and explore how shared libraries work when it comes to a tool like <code>\/usr\/bin\/zip<\/code>\u00a0that\u2019s included or installable with major Linux distributions.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-10934\" src=\"https:\/\/www.cloudsavvyit.com\/p\/uploads\/2021\/04\/09dd8c26.png?trim=1,1&amp;bg-color=000&amp;pad=1,1\" alt=\"Using ldd in Linux\" width=\"690\" height=\"183\" onload=\"pagespeed.lazyLoadImages.loadIfVisibleAndMaybeBeacon(this);\" onerror=\"this.onerror=null;pagespeed.lazyLoadImages.loadIfVisibleAndMaybeBeacon(this);\"\/><\/p>\n<p>Here, we changed directories to <code>\/usr\/bin<\/code> and checked whether the <code>zip<\/code> program\/binary\/executable is present. Finding it present, we next checked the version by invoking it with <code>--version<\/code> and taking only the top two lines of the output by piping the output (using <code>|<\/code>) to avoid the long output given otherwise.<\/p>\n<p>Finally, we used the <code>ldd<\/code> tool (a program that prints shared object dependencies) to see what libraries the executable requires. As we can see, the program requires four shared libraries. The list of libraries required is usually in the format of the library required, followed by a path where the named library was found already.<\/p>\n<p>For some top-level or special OS-level libraries (like <code>linux-vdso.so.1<\/code>), no such path is shown. However, as long as no error is showing for any entry, you know that it\u2019s fine and available (or preferable). In fact,\u00a0<code>linux-vdso.so.1<\/code> is a special virtual shared object\/library injected into every process by the Linux Kernel, which doesn\u2019t have a physical file on disk for the same. It\u2019s there to make system calls more efficient.<\/p>\n<p>So, let\u2019s break things a little, and rename one of the required libraries so that it can no longer be discovered automatically by the binary:<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-10935\" src=\"https:\/\/www.cloudsavvyit.com\/p\/uploads\/2021\/04\/8266e4bf.png?trim=1,1&amp;bg-color=000&amp;pad=1,1\" alt=\"Error while loading shared libraries and the missing library\" width=\"952\" height=\"154\" onload=\"pagespeed.lazyLoadImages.loadIfVisibleAndMaybeBeacon(this);\" onerror=\"this.onerror=null;pagespeed.lazyLoadImages.loadIfVisibleAndMaybeBeacon(this);\"\/><\/p>\n<p>As you can see, here, we renamed\/moved the file from <code>\/lib\/x86_64-linux-gnu\/libbz2.so.1.0<\/code> to <code>\/lib\/x86_64-linux-gnu\/libbz2.so.1.0.NOT_PRESENT<\/code>. This broke our zip application, and when we try to run it, we get the dreaded <code>error while loading shared libraries<\/code> error. Looking a bit closer, the error message is actually quite descriptive, however:<\/p>\n<pre>zip: error while loading shared libraries: libbz2.so.1.0: cannot open shared object file: No such file or directory&#13;\n<\/pre>\n<p>A seasoned IT engineer will always carefully review any logs and program output\/information presented to him or her before making a call on an issue. It would pay off here, too, as the required file is clearly shown,\u00a0<code>libbz2.so.1.0<\/code>, and the issue is clearly shown also. There\u2019s <code>No such file or directory<\/code>. In other words, <code>libbz2.so.1.0<\/code> is missing!<\/p>\n<p>We can also verify the same with <code>ldd<\/code>, as can be seen in the image above. A clear <code>libbz2.so.1.0 =&gt; not found<\/code> helps us to know what\u2019s happening. Once we clearly understand how dynamically compiled binaries (most of the binaries in the operating system are compiled this way) load and require libraries, and how to see whether one is missing (or being informed of the same via the error message), things don\u2019t look that complicated anymore.<\/p>\n<p>What\u2019s more is that once we know the required library name, a quick search in your favorite search engine will show the additional package to be installed (or reinstalled) to obtain the required library name. Quite often, the package name can even be construed directly from the library name. However, in this case, the name for the runtime library is a bit offset.<\/p>\n<p>There are two types of libraries\u2014runtime libraries and development libraries. In this case, the package name that contains the\u00a0<code>libbz2.so.1.0<\/code>\u00a0library is likely\u00a0<code>bzip2<\/code>,\u00a0and trying to uninstall would likely break various other items, as can be glanced from a long list of programs that will be removed if one tries to uninstall or purge the <code>bzip2<\/code> package.<\/p>\n<p>The second type of library is a development library. These are often required when trying to compile programs and are often even more closely related to their actual library file names. For example, in Ubuntu, simply take the library name and add <code>-dev<\/code>. For example, if we wanted to install the development package related to the <code>libbz2.so.1.0<\/code> package, we could look at installing <code>libbz2-dev<\/code>:<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-10936\" src=\"https:\/\/www.cloudsavvyit.com\/p\/uploads\/2021\/04\/f19c9085.png?trim=1,1&amp;bg-color=000&amp;pad=1,1\" alt=\"Installing a development library\" width=\"543\" height=\"133\" onload=\"pagespeed.lazyLoadImages.loadIfVisibleAndMaybeBeacon(this);\" onerror=\"this.onerror=null;pagespeed.lazyLoadImages.loadIfVisibleAndMaybeBeacon(this);\"\/><\/p>\n<p>Whereas this development library isn\u2019t directly related to our <code>libbz2.so.1.0<\/code> runtime library, it\u2019s helpful to know the naming syntax of most development package names in Ubuntu (prefix of <code>lib<\/code> and suffix of <code>-dev<\/code> with the name of the library in between those) for whenever a certain development library is required (which is most often necessary when compiling software).<\/p>\n<p>Also, suppose that any library somehow became broken. In that case, one of the easiest quick fixes is to purge the library <code>sudo apt purge your_library_name<\/code> command (which would completely purge the library\/program passed), followed by a reinstallation using the <code>sudo apt install your_library_name<\/code> command.<\/p>\n<p>And when you run into a situation similar to the above, where uninstalling the runtime library requires uninstalling\/purging the main program, and where such a purge\/remove is too large a part of the operating system or would affect too many other things, you can use a reinstallation option instead:<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-10937\" src=\"https:\/\/www.cloudsavvyit.com\/p\/uploads\/2021\/04\/9eb9cd58.png?trim=1,1&amp;bg-color=000&amp;pad=1,1\" alt=\"Reinstalling an application or library\" width=\"852\" height=\"237\" onload=\"pagespeed.lazyLoadImages.loadIfVisibleAndMaybeBeacon(this);\" onerror=\"this.onerror=null;pagespeed.lazyLoadImages.loadIfVisibleAndMaybeBeacon(this);\"\/><\/p>\n<pre>sudo apt reinstall bzip2&#13;\n<\/pre>\n<p>It isn\u2019t always this easy, however, although knowing the above (and especially the naming convention in terms of adding <code>-dev<\/code>) helps tremendously when troubleshooting issues and will often fix the issue straight up.<\/p>\n<p>It also helps a lot to know how libraries can be checked using <code>ldd<\/code>, and finally, understanding that a library is just an executable (although not directly) <code>.so<\/code> file that lives in a subdirectory of <code>\/lib<\/code> or in <code>\/usr\/lib<\/code> or other similar directories.<\/p>\n<p>Sometimes, libraries and\/or packages conflict with one another, or certain packages require certain library versions, or certain libraries require other libraries, at specific versions themselves. Yes, it gets a little complex. It\u2019s also somewhat easy, when it becomes this complex, to slightly mess up a system. At times, it\u2019s even quite possible to completely break an operating system installation due to moving a too-important library, etc.<\/p>\n<p>Often, it\u2019s somewhat safer to create a symlink (a virtual link with a given filename, referring\/linking to another existing file or another symlink itself, which in turn points to a real file) for a missing library at an older version, for example, and pointing that symlink to the latest installed version. It doesn\u2019t always work, but just in case it fails, the symlink can be removed, hopefully safer (assuming that no such symlink or file with the same name existed beforehand).<\/p>\n<p>The best way to troubleshoot these more complex problems is to always try an\u00a0<code>apt<\/code> (or a similar package management tool on your operating system) -based solution first. At this point, you will also want to read how to use dkpg to fix apt,\u00a0as it shows you a more granular way to manage packages (Although be careful, as more control comes with more responsibility!).<\/p>\n<p>If all else fails, try to create a symlink, or even manually add the library file. (Please make <a href=\"https:\/\/buradabiliyorum.com\/en\/category\/trip-and-travel\/\" data-internallinksmanager029f6b8e52c=\"10\" title=\"Trip &amp; Travel\" target=\"_blank\" rel=\"noopener\">trip<\/a>le-sure that any file downloaded is virus-free by, for example, checking it with <a rel=\"nofollow noopener\" target=\"_blank\" href=\"http:\/\/virustotal.com\">VirusTotal<\/a>, and it\u2019s always best to use Linux\u2019s vendor-provided repositories to download binaries.)<\/p>\n<p>In extremis, you might also be able to find a library in a neighboring Linux operating system. For example, a Ubuntu executable will run on Mint and vice versa. Copying a library from another PC that you have is also a viable approach at times.<\/p>\n<h2 role=\"heading\" aria-level=\"2\"><span class=\"ez-toc-section\" id=\"Wrapping_Up\"><\/span>Wrapping Up<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p>Fine-grained library management is a skill that takes a lifetime to learn. It\u2019s almost an art. This article has provided the basic information\/know-how and tools to use and has listed some more advanced troubleshooting suggestions for when things become murky, and sooner or later, they will if you\u2019re a frequent user of Linux who regularly installs packages.<\/p>\n<p>When you next see the \u2018Error while loading shared libraries\u2019 error on your Linux machine, you will be better equipped to understand where the issue might come from using a tool like <code>ldd<\/code>, as explained in this article. We also looked at static versus dynamically compiled binaries, and how shared or built-in libraries fit into and work with both.<\/p>\n<p>If you enjoyed this article, you might also like to read the article on <code>dpkg<\/code> linked above as well as How to Add the Universe, Multiverse, and Restricted Repositories in Ubuntu.\n<\/div>\n<blockquote><p><strong><span style=\"color: #ff6600;\">If you liked the article, do not forget to share it with your friends. Follow us on\u00a0<span style=\"color: #ff0000;\"><a style=\"color: #ff0000;\" href=\"https:\/\/news.google.com\/publications\/CAAqBwgKMLG0nwswvr63Aw\" target=\"_blank\" rel=\"nofollow noopener noreferrer\">Google News<\/a><\/span>\u00a0too, click on the star and choose us from your favorites.<\/span><\/strong><\/p><\/blockquote>\n<blockquote>\n<p style=\"text-align: center;\">For forums sites go to <span style=\"color: #ff9900;\"><a style=\"color: #ff9900;\" href=\"https:\/\/forum.buradabiliyorum.com\/\" target=\"_blank\" rel=\"noopener\">Forum.BuradaBiliyorum.Com<\/a><\/span><\/strong><\/p>\n<\/blockquote>\n<blockquote>\n<p style=\"text-align: center;\"><strong>If you want to read more like this article, you can visit our <span style=\"color: #ff9900;\"><a style=\"color: #ff9900;\" href=\"https:\/\/en.buradabiliyorum.com\/technology\/\" target=\"_blank\" rel=\"noopener\">Technology category.<\/a><\/span><\/strong><\/p>\n<\/blockquote>\n<p><span style=\"color: black;\"><a style=\"color: #ff9900;\" href=\"https:\/\/www.cloudsavvyit.com\/10933\/how-to-work-with-shared-object-library-dependencies-in-linux\/\" target=\"_blank\" rel=\"noopener\">Source<\/a><\/span><\/p>\n","protected":false},"excerpt":{"rendered":"<p>&#8220;#How to Work with Shared Object (Library) Dependencies in Linux \u2013 CloudSavvy IT&#8221; Dima Polies\/Shutterstock.com Error while loading shared libraries: the dreaded error that every Linux user will sooner or later run into. Something went wrong with the shared object dependencies (the libraries) used by the executable. Learn how to fix such issues and more!&#8230;<\/p>\n","protected":false},"author":1,"featured_media":300945,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"fifu_image_url":"https:\/\/www.cloudsavvyit.com\/p\/uploads\/2021\/06\/9a3f0be2.png","fifu_image_alt":"","footnotes":""},"categories":[18],"tags":[],"class_list":["post-300944","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-technology"],"_links":{"self":[{"href":"https:\/\/buradabiliyorum.com\/en\/wp-json\/wp\/v2\/posts\/300944","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/buradabiliyorum.com\/en\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/buradabiliyorum.com\/en\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/buradabiliyorum.com\/en\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/buradabiliyorum.com\/en\/wp-json\/wp\/v2\/comments?post=300944"}],"version-history":[{"count":0,"href":"https:\/\/buradabiliyorum.com\/en\/wp-json\/wp\/v2\/posts\/300944\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/buradabiliyorum.com\/en\/wp-json\/wp\/v2\/media\/300945"}],"wp:attachment":[{"href":"https:\/\/buradabiliyorum.com\/en\/wp-json\/wp\/v2\/media?parent=300944"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/buradabiliyorum.com\/en\/wp-json\/wp\/v2\/categories?post=300944"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/buradabiliyorum.com\/en\/wp-json\/wp\/v2\/tags?post=300944"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}