{"id":21734,"date":"2017-03-02T12:16:52","date_gmt":"2017-03-02T12:16:52","guid":{"rendered":"https:\/\/www.testingdocs.com\/questions\/?p=21734"},"modified":"2024-11-16T14:47:10","modified_gmt":"2024-11-16T14:47:10","slug":"how-to-fix-the-error-multiple-definition-of-main","status":"publish","type":"post","link":"https:\/\/www.testingdocs.com\/questions\/how-to-fix-the-error-multiple-definition-of-main\/","title":{"rendered":"How to fix the error: multiple definition of `main&#8217;"},"content":{"rendered":"<h1>Overview<\/h1>\n<p>In this post, we will fix the error multiple definition of `main&#8217; in C++ project. The error occurs if the C++ project has multiples main functions defined in the project.<\/p>\n<h2>Error<\/h2>\n<p>Sample error log:<\/p>\n<p>Documents\/CProjects\/TestingDocsProject\/syntax.cpp:10: multiple definition of `main&#8217;<br \/>\nobj\\Debug\\main.o:\/Documents\/CProjects\/TestingDocsProject\/main.cpp:10: first defined here<\/p>\n<p>&nbsp;<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-21736\" src=\"https:\/\/www.testingdocs.com\/questions\/wp-content\/uploads\/C-Multiple-Definition-of-Main-Error.png\" alt=\"C++ Multiple Definition of Main Error\" width=\"1916\" height=\"1066\" title=\"\" srcset=\"https:\/\/www.testingdocs.com\/questions\/wp-content\/uploads\/C-Multiple-Definition-of-Main-Error.png 1916w, https:\/\/www.testingdocs.com\/questions\/wp-content\/uploads\/C-Multiple-Definition-of-Main-Error-300x167.png 300w, https:\/\/www.testingdocs.com\/questions\/wp-content\/uploads\/C-Multiple-Definition-of-Main-Error-1024x570.png 1024w, https:\/\/www.testingdocs.com\/questions\/wp-content\/uploads\/C-Multiple-Definition-of-Main-Error-768x427.png 768w, https:\/\/www.testingdocs.com\/questions\/wp-content\/uploads\/C-Multiple-Definition-of-Main-Error-1536x855.png 1536w\" sizes=\"auto, (max-width: 1916px) 100vw, 1916px\" \/><\/p>\n<p>In this example, the source code files syntax.cpp and main.cpp contains the main() routine defined.<\/p>\n<h2>Error Fix<\/h2>\n<p>The main function is the entry point for the C++ program execution.<br \/>\nThe fix for the error is to scan the source files listed in the build log and remove the unwanted main routines in the respective files. We can have one definition of the main function for the project to run.<\/p>\n<p>Alternatively, we can also remove source code files from the project which has multiple definitions of the main routine.<\/p>\n<p>That&#8217;s it. This will resolve the error in the project.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Overview In this post, we will fix the error multiple definition of `main&#8217; in C++ project. The error occurs if the C++ project has multiples main functions defined in the project. Error Sample error log: Documents\/CProjects\/TestingDocsProject\/syntax.cpp:10: multiple definition of `main&#8217; obj\\Debug\\main.o:\/Documents\/CProjects\/TestingDocsProject\/main.cpp:10: first defined here &nbsp; In this example, the source code files syntax.cpp and main.cpp [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[421],"tags":[],"class_list":["post-21734","post","type-post","status-publish","format-standard","hentry","category-c","has-post-title","has-post-date","has-post-category","has-post-tag","has-post-comment","has-post-author",""],"_links":{"self":[{"href":"https:\/\/www.testingdocs.com\/questions\/wp-json\/wp\/v2\/posts\/21734","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.testingdocs.com\/questions\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.testingdocs.com\/questions\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.testingdocs.com\/questions\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.testingdocs.com\/questions\/wp-json\/wp\/v2\/comments?post=21734"}],"version-history":[{"count":6,"href":"https:\/\/www.testingdocs.com\/questions\/wp-json\/wp\/v2\/posts\/21734\/revisions"}],"predecessor-version":[{"id":23199,"href":"https:\/\/www.testingdocs.com\/questions\/wp-json\/wp\/v2\/posts\/21734\/revisions\/23199"}],"wp:attachment":[{"href":"https:\/\/www.testingdocs.com\/questions\/wp-json\/wp\/v2\/media?parent=21734"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.testingdocs.com\/questions\/wp-json\/wp\/v2\/categories?post=21734"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.testingdocs.com\/questions\/wp-json\/wp\/v2\/tags?post=21734"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}