

{"id":28,"date":"2020-06-15T18:39:33","date_gmt":"2020-06-15T22:39:33","guid":{"rendered":"https:\/\/sites.temple.edu\/vahid\/?p=28"},"modified":"2020-06-15T18:39:33","modified_gmt":"2020-06-15T22:39:33","slug":"executables-and-libraries","status":"publish","type":"post","link":"https:\/\/sites.temple.edu\/vahid\/2020\/06\/15\/executables-and-libraries\/","title":{"rendered":"Executables and Libraries"},"content":{"rendered":"\n<p>Static and dynamic link libraries (or shared object files) are two essential components in modern operating systems.<\/p>\n\n\n\n<p>Linux has very interesting tools to interact with executable files and corresponding libraries. The following quick note comes from the following link.<\/p>\n\n\n\n<p><a href=\"https:\/\/amir.rachum.com\/blog\/2016\/09\/17\/shared-libraries\/\">https:\/\/amir.rachum.com\/blog\/2016\/09\/17\/shared-libraries\/<\/a><\/p>\n\n\n\n<p><code>$ readelf -h main<\/code><\/p>\n\n\n\n<p>can be used to find header information about the executable.<\/p>\n\n\n\n<p><code>$ readelf -d main | grep NEEDED<\/code><\/p>\n\n\n\n<p>can be used to show the dependency of the executable to libraries.<\/p>\n\n\n\n<p><code>$ ldd main<\/code><\/p>\n\n\n\n<p>will show the dependency <strong><em>hierarchy<\/em><\/strong> of an executable.<\/p>\n\n\n\n<p>Each shared library in our dependencies is searched in the following locations, in order:<\/p>\n\n\n\n<ol class=\"wp-block-list\"><li>Directories listed in the executable\u2019s <code><span class=\"has-inline-color has-vivid-cyan-blue-color\">rpath<\/span><\/code>.<\/li><li>Directories in the <code><span class=\"has-inline-color has-vivid-cyan-blue-color\">LD_LIBRARY_PATH<\/span><\/code> environment variable, which contains colon-separated list of directories (e.g., \/path\/to\/libdir:\/another\/path)<\/li><li>Directories listed in the executable\u2019s <code><span class=\"has-inline-color has-vivid-cyan-blue-color\">runpath<\/span><\/code>.<\/li><li>The list of directories in the file <code><span class=\"has-inline-color has-vivid-cyan-blue-color\">\/etc\/ld.so.conf<\/span><\/code>. This file can include other files, but it is basically a list of directories &#8211; one per line.<\/li><li>Default system libraries &#8211; usually <code><span class=\"has-inline-color has-vivid-cyan-blue-color\">\/lib<\/span><\/code> and <span class=\"has-inline-color has-vivid-cyan-blue-color\"><code>\/usr\/lib<\/code><\/span> (skipped if compiled with <code>-z nodefaultlib<\/code>).<\/li><\/ol>\n\n\n\n<p><code>$echo $LD_LIBRARY_PATH<\/code><\/p>\n\n\n\n<p>can be used to show the current default search paths to find shared libraries.<\/p>\n\n\n\n<p><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Static and dynamic link libraries (or shared object files) are two essential components in modern operating systems. Linux has very interesting tools to interact with&#8230;<\/p>\n<div class=\"more-link-wrapper\"><a class=\"more-link\" href=\"https:\/\/sites.temple.edu\/vahid\/2020\/06\/15\/executables-and-libraries\/\">Continue reading<span class=\"screen-reader-text\">Executables and Libraries<\/span><\/a><\/div>\n","protected":false},"author":18759,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[14],"tags":[25,27,24],"class_list":["post-28","post","type-post","status-publish","format-standard","hentry","category-tools","tag-c","tag-libraries","tag-linux","entry"],"_links":{"self":[{"href":"https:\/\/sites.temple.edu\/vahid\/wp-json\/wp\/v2\/posts\/28","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/sites.temple.edu\/vahid\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/sites.temple.edu\/vahid\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/sites.temple.edu\/vahid\/wp-json\/wp\/v2\/users\/18759"}],"replies":[{"embeddable":true,"href":"https:\/\/sites.temple.edu\/vahid\/wp-json\/wp\/v2\/comments?post=28"}],"version-history":[{"count":0,"href":"https:\/\/sites.temple.edu\/vahid\/wp-json\/wp\/v2\/posts\/28\/revisions"}],"wp:attachment":[{"href":"https:\/\/sites.temple.edu\/vahid\/wp-json\/wp\/v2\/media?parent=28"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/sites.temple.edu\/vahid\/wp-json\/wp\/v2\/categories?post=28"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/sites.temple.edu\/vahid\/wp-json\/wp\/v2\/tags?post=28"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}