Author Topic: 2 same files with function main() in workspace-during compilation error.  (Read 389 times)

Offline aorlecki

  • Single posting newcomer
  • *
  • Posts: 2
I'm working with Code::Block a few days.
Why this happens at C++Editor  Code:: Blocks, after adding additional empty files ( CTR-SHIFT-N  untitled.cpp )  in any projects and copying content from working code from main.cpp in order to have a copy on hand, appears info error: "multiple definitions of `main' "during compiling-Is that mean in this editor is not possible to have  function main() in current project  at each file.
The compiler is working well without error when removing this additional copied files from the project and compiling possible is again.

Offline oBFusCATed

  • Developer
  • Lives here!
  • *****
  • Posts: 10399
Re: 2 same files with function main() in workspace-during compilation error.
« Reply #1 on: October 05, 2017, 08:40:37 pm »
Because you're not allowed to have two functions named the same in the same executable.

Have to setup multiple projects or multiple targets in a project and then add the two files to two separate projects or targets which build different executables.
<debugger plugin maintainer>
(most of the time I ignore long posts)
[strangers don't send me private messages, I'll ignore them; post a topic in the forum, but first read the rules!]

Offline aorlecki

  • Single posting newcomer
  • *
  • Posts: 2
Re: 2 same files with function main() in workspace-during compilation error.
« Reply #2 on: October 05, 2017, 09:24:17 pm »
Thanks for helping answer and clarify my fresh approach with Code::Blocks

It is a good thing to have a parallel temporary assistant workspace in using in the main project ->>I will follow Your advice to have separate projects and not for build different executables but for keeping order. You may work without problems to remember when and how to add class or other elements. -It is also a solution for that to have separated programming editor: notepad++ , vim or even any kind of simple notepad to have that in hand during work.
Regards