{"id":600,"date":"2022-08-30T15:04:03","date_gmt":"2022-08-30T15:04:03","guid":{"rendered":"https:\/\/unknownerror.org\/index.php\/2013\/11\/09\/how-to-make-gcc-ld-iterate-over-many-l-library-when-using-static-collection-of-common-programming-errors\/"},"modified":"2022-08-30T15:04:03","modified_gmt":"2022-08-30T15:04:03","slug":"how-to-make-gcc-ld-iterate-over-many-l-library-when-using-static-collection-of-common-programming-errors","status":"publish","type":"post","link":"https:\/\/unknownerror.org\/index.php\/2022\/08\/30\/how-to-make-gcc-ld-iterate-over-many-l-library-when-using-static-collection-of-common-programming-errors\/","title":{"rendered":"How to make gcc\/ld iterate over many &#39;-l library&#39; when using -static?-Collection of common programming errors"},"content":{"rendered":"<p>A tick is, whenever possible, to add a static reference to an object of the class (or to the function) that were not linked in another cpp file of the same library (or in another library already used).<\/p>\n<p>I have this situation:<\/p>\n<ul>\n<li>library A with class clsA in clsA.cpp that gives the error<\/li>\n<li>library A with foo.cpp that gives no reference errors<\/li>\n<li>library B that uses class clsA<\/li>\n<li>Application uses both libraries and uses classes\/functions from foo.cpp<\/li>\n<\/ul>\n<p>I get the unresolved reference in Application while using the object in library B that uses the clsA class.<\/p>\n<p>Linking Application with library A and B give me the error. Since i use CodeLite, it&#8217;s hard to change library order. I simply put a static object in foo.cpp:<\/p>\n<pre><code>#include \"clsA.h\"\nclsA objA;\n<\/code><\/pre>\n<p>The linker now see that clsA are referenced in library A (between foo.cpp) and will link correctly in application because foo.cpp were already linked.<\/p>\n<p>But the trick works even if the object were created in a dummy function, never called, so the object would never been allocated:<\/p>\n<pre><code>\/\/ foo.cpp\n#include \"clsA.h\"\nvoid dummyf()\n{\n   clsA objA;\n}\n<\/code><\/pre>\n<p id=\"rop\"><small>Originally posted 2013-11-09 21:07:09. <\/small><\/p>","protected":false},"excerpt":{"rendered":"<p>A tick is, whenever possible, to add a static reference to an object of the class (or to the function) that were not linked in another cpp file of the same library (or in another library already used). I have this situation: library A with class clsA in clsA.cpp that gives the error library A [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-600","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"_links":{"self":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts\/600","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/comments?post=600"}],"version-history":[{"count":0,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts\/600\/revisions"}],"wp:attachment":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/media?parent=600"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/categories?post=600"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/tags?post=600"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}