{"id":5857,"date":"2020-03-31T09:34:44","date_gmt":"2020-03-31T16:34:44","guid":{"rendered":"https:\/\/visualgdb.com\/w\/?p=5857"},"modified":"2020-10-27T12:21:50","modified_gmt":"2020-10-27T19:21:50","slug":"libraries-and-other-linker-inputs","status":"publish","type":"post","link":"https:\/\/visualgdb.com\/documentation\/linkerinputs\/","title":{"rendered":"Libraries and Other Linker Inputs"},"content":{"rendered":"<p>VisualGDB uses the standard Linux way of specifying libraries used by the projects that relies on 3 different parameters:<a href=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2020\/03\/inputs.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-5858\" src=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2020\/03\/inputs.png\" alt=\"\" width=\"683\" height=\"105\" \/><\/a><\/p>\n<ol>\n<li><strong>Library directories.<\/strong> These are the directories where the GNU linker will search for libraries specified in &#8220;Library names&#8221;. Locations like \/usr\/lib will be searched by default and do not need to be specified.<\/li>\n<li><strong>Library names.<\/strong> This line contains <strong>short library names<\/strong> of libraries that should be linked with the project. The short library names do not contain the &#8216;<strong>lib<\/strong>&#8216; prefix or the <strong>.a<\/strong> extension. E.g. in order to link with <strong>libpthread.a<\/strong> and <strong>libm.a<\/strong> this line should contain &#8220;<strong>pthread m<\/strong>&#8220;. If you need to use a specific version of the library (e.g. <strong>libboost_system.so.1.61.0<\/strong>), you can specify it here prefixed with a colon (e.g. &#8220;<strong>:libboost_system.so.1.61.0<\/strong>&#8220;), or enter the full path to the library in the <strong>Additional Linker Inputs<\/strong> field.<\/li>\n<li><strong>Additional linker inputs.<\/strong> This line can specify full paths to additional library or object files that should be linked with the project. This can be used to link against a specific version of a library, e.g. <strong>\/usr\/lib\/i386-linux-gnu\/libpthread.so<\/strong>. If you are using a cross-toolchain, use the &#8216;=&#8217; prefix to specify a path inside the sysroot directory (e.g. =\/<strong>usr\/lib\/arm-linux-gnueabihf\/libboost_system.so.1.61.0 <\/strong>will expand to <strong>c:\\SysGCC\\raspberry\\arm-linux-gnueabihf\\sysroot\\usr\\lib\\arm-linux-gnueabihf\\libboost_system.so.1.61.0<\/strong>)<\/li>\n<\/ol>\n<p>It is recommended to specify libraries using the short names and directories, however if this causes problems (e.g. when using cross-compilation toolchains), it may be helpful to specify full paths to all necessary libraries using the &#8220;Additional Linker Inputs&#8221; line.<\/p>\n<h2>Diagnosing Linker Problems<\/h2>\n<p>The 2 most common types of linker errors are:<\/p>\n<ul>\n<li><strong>&#8220;Undefined reference to &lt;symbol&gt;&#8221;<\/strong> error. It is typically caused by missing library names in linker settings. See <a href=\"https:\/\/visualgdb.com\/tutorials\/linux\/libraries\/diagnosing\/\">this tutorial<\/a> for detailed troubleshooting instructions.<\/li>\n<li><strong>&#8220;Cannot find &lt;library&gt;&#8221;<\/strong> error. It happens when a library is specified in the project settings, but is not physically present in the library search path. You can resolve it by locating the physical library file (<strong>lib&lt;name&gt;.a<\/strong> or <strong>lib&lt;name&gt;.so<\/strong>) and copying it into one of the standard library directories, or adding its directory to the library search path. <strong>Note that if you are using a cross-toolchain, the library must be copied to the machine with the toolchain. In most of the cases, it can be done by pressing the &#8220;Synchronize Sysroot&#8221; button in VisualGDB Project Properties.<\/strong><\/li>\n<\/ul>\n<p>You can force the linker to output a detailed log about the process of finding libraries. This can be accomplished by adding &#8220;<strong>-Wl,-verbose<\/strong>&#8221; to the linker command line (or using the &#8220;Verbose Mode&#8221; setting for MSBuild projects):<a href=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2020\/03\/verbose.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-5859\" src=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2020\/03\/verbose.png\" alt=\"\" width=\"684\" height=\"558\" \/><\/a>Building the project with the <strong>-Wl,-verbose<\/strong> flag will produce a detailed output about each linker&#8217;s attempt to open a library:<\/p>\n<pre class=\"\">attempt to open \/usr\/lib\/gcc\/i686-linux-gnu\/4.8\/..\/..\/..\/i386-linux-gnu\/crt1.o succeeded\r\n\/usr\/lib\/gcc\/i686-linux-gnu\/4.8\/..\/..\/..\/i386-linux-gnu\/crt1.o\r\nattempt to open \/usr\/lib\/gcc\/i686-linux-gnu\/4.8\/..\/..\/..\/i386-linux-gnu\/crti.o succeeded\r\n\/usr\/lib\/gcc\/i686-linux-gnu\/4.8\/..\/..\/..\/i386-linux-gnu\/crti.o\r\nattempt to open \/usr\/lib\/gcc\/i686-linux-gnu\/4.8\/crtbegin.o succeeded\r\n\/usr\/lib\/gcc\/i686-linux-gnu\/4.8\/crtbegin.o\r\nattempt to open VisualGDB\/Debug\/LibraryDemo.o succeeded\r\nVisualGDB\/Debug\/LibraryDemo.o\r\nattempt to open \/usr\/lib\/gcc\/i686-linux-gnu\/4.8\/libstdc++.so succeeded\r\n-lstdc++ (\/usr\/lib\/gcc\/i686-linux-gnu\/4.8\/libstdc++.so)\r\nattempt to open \/usr\/lib\/gcc\/i686-linux-gnu\/4.8\/libm.so failed\r\nattempt to open \/usr\/lib\/gcc\/i686-linux-gnu\/4.8\/libm.a failed\r\nattempt to open \/usr\/lib\/gcc\/i686-linux-gnu\/4.8\/..\/..\/..\/i386-linux-gnu\/libm.so succeeded\r\n-lm (\/usr\/lib\/gcc\/i686-linux-gnu\/4.8\/..\/..\/..\/i386-linux-gnu\/libm.so)\r\nattempt to open \/usr\/lib\/gcc\/i686-linux-gnu\/4.8\/libgcc_s.so succeeded\r\n-lgcc_s (\/usr\/lib\/gcc\/i686-linux-gnu\/4.8\/libgcc_s.so)\r\nattempt to open \/usr\/lib\/gcc\/i686-linux-gnu\/4.8\/libgcc.so failed\r\nattempt to open \/usr\/lib\/gcc\/i686-linux-gnu\/4.8\/libgcc.a succeeded\r\nattempt to open \/usr\/lib\/gcc\/i686-linux-gnu\/4.8\/libc.so failed\r\nattempt to open \/usr\/lib\/gcc\/i686-linux-gnu\/4.8\/libc.a failed\r\nattempt to open \/usr\/lib\/gcc\/i686-linux-gnu\/4.8\/..\/..\/..\/i386-linux-gnu\/libc.so succeeded\r\nopened script file \/usr\/lib\/gcc\/i686-linux-gnu\/4.8\/..\/..\/..\/i386-linux-gnu\/libc.so\r\nopened script file \/usr\/lib\/gcc\/i686-linux-gnu\/4.8\/..\/..\/..\/i386-linux-gnu\/libc.so\r\nattempt to open \/lib\/i386-linux-gnu\/libc.so.6 succeeded\r\n\/lib\/i386-linux-gnu\/libc.so.6\r\nattempt to open \/usr\/lib\/i386-linux-gnu\/libc_nonshared.a succeeded\r\n(\/usr\/lib\/i386-linux-gnu\/libc_nonshared.a)elf-init.oS\r\nattempt to open \/lib\/i386-linux-gnu\/ld-linux.so.2 succeeded\r\n\/lib\/i386-linux-gnu\/ld-linux.so.2\r\nattempt to open \/usr\/lib\/gcc\/i686-linux-gnu\/4.8\/libgcc_s.so succeeded\r\n-lgcc_s (\/usr\/lib\/gcc\/i686-linux-gnu\/4.8\/libgcc_s.so)\r\nattempt to open \/usr\/lib\/gcc\/i686-linux-gnu\/4.8\/libgcc.so failed\r\nattempt to open \/usr\/lib\/gcc\/i686-linux-gnu\/4.8\/libgcc.a succeeded\r\nattempt to open \/usr\/lib\/gcc\/i686-linux-gnu\/4.8\/crtend.o succeeded\r\n\/usr\/lib\/gcc\/i686-linux-gnu\/4.8\/crtend.o\r\nattempt to open \/usr\/lib\/gcc\/i686-linux-gnu\/4.8\/..\/..\/..\/i386-linux-gnu\/crtn.o succeeded\r\n\/usr\/lib\/gcc\/i686-linux-gnu\/4.8\/..\/..\/..\/i386-linux-gnu\/crtn.o\r\nlibm.so.6 needed by \/usr\/lib\/gcc\/i686-linux-gnu\/4.8\/libstdc++.so\r\nfound libm.so at \/usr\/lib\/gcc\/i686-linux-gnu\/4.8\/..\/..\/..\/i386-linux-gnu\/libm.so\r\nld-linux.so.2 needed by \/usr\/lib\/gcc\/i686-linux-gnu\/4.8\/libstdc++.so\r\nfound ld-linux.so.2 at \/lib\/i386-linux-gnu\/ld-linux.so.2\r\nlibgcc_s.so.1 needed by \/usr\/lib\/gcc\/i686-linux-gnu\/4.8\/libstdc++.so\r\nfound libgcc_s.so at \/usr\/lib\/gcc\/i686-linux-gnu\/4.8\/libgcc_s.so<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>VisualGDB uses the standard Linux way of specifying libraries used by the projects that relies on 3 different parameters: Library<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[199],"tags":[],"_links":{"self":[{"href":"https:\/\/visualgdb.com\/w\/wp-json\/wp\/v2\/posts\/5857"}],"collection":[{"href":"https:\/\/visualgdb.com\/w\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/visualgdb.com\/w\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/visualgdb.com\/w\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/visualgdb.com\/w\/wp-json\/wp\/v2\/comments?post=5857"}],"version-history":[{"count":4,"href":"https:\/\/visualgdb.com\/w\/wp-json\/wp\/v2\/posts\/5857\/revisions"}],"predecessor-version":[{"id":7065,"href":"https:\/\/visualgdb.com\/w\/wp-json\/wp\/v2\/posts\/5857\/revisions\/7065"}],"wp:attachment":[{"href":"https:\/\/visualgdb.com\/w\/wp-json\/wp\/v2\/media?parent=5857"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/visualgdb.com\/w\/wp-json\/wp\/v2\/categories?post=5857"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/visualgdb.com\/w\/wp-json\/wp\/v2\/tags?post=5857"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}