{"id":13173,"date":"2022-06-09T15:14:25","date_gmt":"2022-06-09T15:14:25","guid":{"rendered":"http:\/\/blog.bachi.net\/?p=13173"},"modified":"2022-06-09T15:14:25","modified_gmt":"2022-06-09T15:14:25","slug":"gcc-multiple-definition-first-defined-here-errors","status":"publish","type":"post","link":"https:\/\/blog.bachi.net\/?p=13173","title":{"rendered":"gcc &#8220;Multiple definition&#8221;, &#8220;first defined here&#8221; errors"},"content":{"rendered":"<p><a href=\"https:\/\/gcc.gnu.org\/onlinedocs\/gcc\/Code-Gen-Options.html\">Options for Code Generation Conventions<\/a><\/p>\n<p><code>-fcommon<\/code><br \/>\nIn C code, this option controls the placement of global variables defined without an initializer, known as tentative definitions in the C standard. Tentative definitions are distinct from declarations of a variable with the extern keyword, which do not allocate storage.<\/p>\n<p>The default is <code>-fno-common<\/code>, which specifies that the compiler places uninitialized global variables in the BSS section of the object file. This inhibits the merging of tentative definitions by the linker so you get a multiple-definition error if the same variable is accidentally defined in more than one compilation unit.<\/p>\n<p>The <code>-fcommon<\/code> places uninitialized global variables in a common block. This allows the linker to resolve all tentative definitions of the same variable in different compilation units to the same object, or to a non-tentative definition. This behavior is inconsistent with C++, and on many targets implies a speed and code size penalty on global variable references. <strong>It is mainly useful to enable legacy code to link without errors.<\/strong><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Options for Code Generation Conventions -fcommon In C code, this option controls the placement of global variables defined without an initializer, known as tentative definitions in the C standard. Tentative definitions are distinct from declarations of a variable with the extern keyword, which do not allocate storage. The default is -fno-common, which specifies that the [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-13173","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"_links":{"self":[{"href":"https:\/\/blog.bachi.net\/index.php?rest_route=\/wp\/v2\/posts\/13173","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/blog.bachi.net\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blog.bachi.net\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blog.bachi.net\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/blog.bachi.net\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=13173"}],"version-history":[{"count":1,"href":"https:\/\/blog.bachi.net\/index.php?rest_route=\/wp\/v2\/posts\/13173\/revisions"}],"predecessor-version":[{"id":13174,"href":"https:\/\/blog.bachi.net\/index.php?rest_route=\/wp\/v2\/posts\/13173\/revisions\/13174"}],"wp:attachment":[{"href":"https:\/\/blog.bachi.net\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=13173"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blog.bachi.net\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=13173"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blog.bachi.net\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=13173"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}