1

I'm on Mac OS Mojave(Version 10.14), using Eclipse Photon. I have a single C++ project(which won't show up in the C++ perspective, only the Java perspective), and I'd like multiple packages/folders for various things. For example:

- MyCPPProject - School - Lab01.cpp - Lab02.cpp - Personal - File01.cpp - File02.cpp

All of the C++ files will have main methods(which is why I can't run them if they're in the same project). All of the files will be "simple," meaning that they will not do anything beyond competitive programming(so nothing beyond cin/cout or scanf).

The Internet says I need a new project for every main method. Does anyone have any ideas so that I can keep my programs in 1 project?

Thanks in advance.

Sumanth Ratna
  • 33
  • 1
  • 2
  • 10
  • " I don't need an exe file or any of that, I just want to be able to run my CPP files.". Uh - *what*??? ALSO: If your C++ project won't show in the CDT perspective ... that definitely sounds like a problem ;) FINALLY: Rather than have "main methods in all your C++ files"... consider using a unit test framework instead. Here's a video on using Google Test from Eclipse/CDT: https://www.linkedin.com/learning/test-driven-development-in-c-plus-plus/set-up-google-test-with-eclipse – paulsm4 Oct 20 '18 at 03:28
  • @paulsm4 Sorry about that statement, I've removed it so it doesn't confuse others. I'm a beginner, so what I'm looking for is just something that can run my C++ files, and I'd prefer they're in one project and in Eclipse. I'll look into unit testing, thanks for the suggestion. – Sumanth Ratna Oct 20 '18 at 03:33
  • 3
    Your question seems very similar to [this one](https://stackoverflow.com/questions/52826462/how-to-setup-eclipse-with-c-for-university-work), see the answers there. – HighCommander4 Oct 20 '18 at 03:44
  • Visual studio has a 'solution'; you can group many projects with different `main`s. – forthe Oct 20 '18 at 04:06
  • Create a `Makefile` project and use your own `Makefile`. – Galik Oct 20 '18 at 06:08

1 Answers1

3
  • The way Java works, you can have a different static void main(String[] args) for every Java class. Neither C nor C++ work like that: you're limited to exactly one "main()" per .exe.

  • That, in turn, means that you must define a separate project in Eclipse for each separate .exe. That's just the way it is :)

  • Eclipse, however, allows you to "group" projects into "Working Sets":

    What is a working set and how do I use it?

    So if you wanted to, you could organize your projects into "School" and "Personal", filtering out one or the other as you wish.

  • Finally, there are C/C++ "Online Fiddles" that allow you to easily run small, standalone .cpp files and that you might prefer over Eclipse, MSVS or CodeBlocks:

    List of Online C++ Compilers

'Hope that helps!

paulsm4
  • 114,292
  • 17
  • 138
  • 190