{"id":1321,"date":"2023-02-02T18:45:07","date_gmt":"2023-02-02T18:45:07","guid":{"rendered":"https:\/\/ibex.tech\/c\/?p=1321"},"modified":"2023-02-02T18:45:07","modified_gmt":"2023-02-02T18:45:07","slug":"multiple-definition-of-errors","status":"publish","type":"post","link":"https:\/\/ibex.tech\/c\/compilers\/gcc-compiler\/errors\/multiple-definition-of-errors","title":{"rendered":"<a href=\"https:\/\/stackoverflow.com\/questions\/75324044\/esp32-compiler-giving-multiple-definition-of-errors\">&#8220;multiple definition of&#8221; errors<\/a>"},"content":{"rendered":"\n<h4 class=\"wp-block-heading\">Using a local variable of the same name in another part of the application<\/h4>\n\n\n\n<p class=\"wp-block-paragraph\">Declaring a variable like this:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>int MyVariableName;<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">creates it as visible across all translation units. Even if you don&#8217;t use it as &#8220;extern int MyVariableName;&#8221; somewhere else, it&#8217;s still visible across all files.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">If you go and do the same thing again, create a variable of the same name, even though you are only using it locally within that file and aren&#8217;t using extern, you&#8217;re going to get a GCC &#8220;multiple definition of&#8221; error because the linker tries to link them together and it&#8217;s see a conflict. <\/p>\n\n\n\n<h5 class=\"wp-block-heading\">It should be static<\/h5>\n\n\n\n<pre class=\"wp-block-code\"><code>static int MyVariableName;<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">The static keyword creates a variable that is not visible across translation units.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Using a local variable of the same name in another part of the application Declaring a variable like this: creates it as visible across all translation units. Even if you don&#8217;t use it as &#8220;extern int MyVariableName;&#8221; somewhere else, it&#8217;s still visible across all files. If you go and do the same thing again, create [&hellip;]<\/p>\n","protected":false},"author":5,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[110],"tags":[],"class_list":["post-1321","post","type-post","status-publish","format-standard","hentry","category-errors"],"_links":{"self":[{"href":"https:\/\/ibex.tech\/c\/wp-json\/wp\/v2\/posts\/1321","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/ibex.tech\/c\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/ibex.tech\/c\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/ibex.tech\/c\/wp-json\/wp\/v2\/users\/5"}],"replies":[{"embeddable":true,"href":"https:\/\/ibex.tech\/c\/wp-json\/wp\/v2\/comments?post=1321"}],"version-history":[{"count":1,"href":"https:\/\/ibex.tech\/c\/wp-json\/wp\/v2\/posts\/1321\/revisions"}],"predecessor-version":[{"id":1322,"href":"https:\/\/ibex.tech\/c\/wp-json\/wp\/v2\/posts\/1321\/revisions\/1322"}],"wp:attachment":[{"href":"https:\/\/ibex.tech\/c\/wp-json\/wp\/v2\/media?parent=1321"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/ibex.tech\/c\/wp-json\/wp\/v2\/categories?post=1321"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/ibex.tech\/c\/wp-json\/wp\/v2\/tags?post=1321"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}