Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9248083
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T09:53:01+00:00 2026-06-18T09:53:01+00:00

When I run a Java Program on Eclipse, each time I run a file,

  • 0

When I run a Java Program on Eclipse, each time I run a file, Compiler will check does it has main, if it has, I can run. And if not, I cannot.

But when I run a C++ Program (CDT) on Eclipse using MinGW, at Compiler doesn’t work like that. After I compile, don’t matter I run from which file, Compiler will search whole project to find ONE MAIN So, if I has many main file, I will receive error.

Please tell me in Eclipse, how to treat C++ Compiler to have multi main file and work like on Java: it just find main on which file I run from.

@: I have multi main file just for debugging purpose. !!!

Thanks 🙂

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-18T09:53:01+00:00Added an answer on June 18, 2026 at 9:53 am

    unlike java in a C/C++ you can only have one main:

    The main() function is special; normally every C and C++ program must
    define it exactly once.

    ( source )

    But: As a workaround you can use preprocessor to decide which of your main‘s you want to use.

    Example:

    #ifdef FIRST_MAIN
    int main(int argc, char** argv)
    {
        printf("first");
    
        return (EXIT_SUCCESS);
    }
    #elif SECOND_MAIN
    int main(int argc, char** argv)
    {
        printf("second");
    
        return (EXIT_SUCCESS);
    }
    #else
    int main(int argc, char** argv)
    {
        printf("default");
    
        return (EXIT_SUCCESS);
    }
    #endif
    

    Now you can decide wich one you want to use by setting proper flag at compiletime. If none is set you’ll use the default one (#else part).

    Alternative: Exclude all your files containing a main-function from compilation and include only the one you need. However, this will only work if those files dont contain more than the main.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I can't run the java program in the CMD,but it's OK in the eclipse.
I would like to compile my Java program in Eclipse but not to run
How do you run a java program that requires input from a file in
Whenever I run a program in eclipse whose configuration is Eclipse Java EE IDE
My Java program crashes (in Eclipse) when I load in a fairly large file.
Every Java program I run in eclipse, no matter how different, gives a console
I have a Java code that can run correctly in eclipse. I need to
I am able to run a Java program through Eclipse by setting the VM
I have several launch configurations in Eclipse each launching the same Java program but
I'm using Eclipse to run java program class, while I run it i got

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.