Multiple main CPP files in VisualStudio?
May be the most simple solution is to use multiple build configurations. Just create a number of build configurations define an entry point for each of them.
Put those main
functions in separate namespaces and then define, which one do you want to run, eg.
File1.cpp
namespace F1
{
int main(int argc, char * argv[])
{
// ...
}
}
The-real-main.cpp
int main(int argc, char * argv[])
{
if (whatever)
return F1::main(argc, argv);
}
Edit: In response to additional information.
C++ is not Java and VS is not Eclipse :) The natural way to maintain multiple programs at once in VS is to put multiple projects (one for each executable or library) in a single solution. If you want to run a project, simply right-click it in Solution Explorer
, select Set as Startup Project
, and then click the Start
button to run it.
To add a project to solution, right-click the solution and choose Add
| New project...
or Add
| Existing project
.
In Visual studio:
Create one "Solution" - under the solution one can create multiple "projects". Each project will compile separately into an executable. Compiling is done as normal other than "unloading" the unneeded projects. In order to reopen one of the other projects simply choose "reload project" from the solutions explorer.
This function is useful for study/organizational purposes where one is grouping source files in a common "folder" for easy search and access while still compiling/debugging separately. The main advantage from what I can tell is that one can easily navigate ones projects using the solution explorer.
I haven't worked OpenCV, but it uses cmake, and has a CMakeLists.txt in the sample directory. There's some discussion about building the samples using cmake here.
Cmake doesn't build anything itself, it generates build scripts for the target platform, and should be able to create Solution and Project files that you can load into Visual Studio.