shinzou
shinzou

Reputation: 6192

How to run multiple different items in the same project?

Is it possible to have in tabs and run multiple different items in the same project, for example:

enter image description here

When I press ctrl+f5 it will either run only the first item or return an error that there's more than one main().

I'm asking this because currently, in order to run multiple different programs I have to make a new project, then add an item, then set that project as start up project, this is really inefficient and annoying and I can't easily switch between tabs like that.

Note: this is for .cpp projects/items.

Upvotes: 2

Views: 6098

Answers (1)

Jonathan Mee
Jonathan Mee

Reputation: 38919

You cannot have more than one main in a project.

However you can modify a projects run command, per Microsoft:

  1. Select the solution in Solution Explorer and then choose "Properties" on the context menu.
  2. Select "Common Properties", "Startup Project" on the "Properties" dialog box.
  3. For each project that you want to change, choose either "Start", "Start without debugging", or "None".

EDIT:

So you're saying rather than wanting to run in parallel you want to build in parallel, in the same project.

That's a really nasty hack as described here: https://stackoverflow.com/a/4775245/2642059

Just bear in mind if you try you're going against Visual Studio's design. Think of it like using a pistol to bring down an elephant cause you don't like how long it takes to load the elephant gun.

EDIT:

Before:

Test.cpp:

int main(){
    return 0;
}

Test2.cpp:

int main(){
    return 2;
}

After:

Test.cpp

int test(){
    return 0;
}

Test2.cpp

int test2(){
    return 2;
}

main.cpp

int main(int argc, char* argv[]){

    if(argc > 1 && atoi(argv[1]) == 2){
        return test2();
    }
    else
    {
        return test();
    }
}

Upvotes: 1

Related Questions