开发者

Choosing which main function to use in Visual C++ 2010

开发者 https://www.devze.com 2023-03-25 17:43 出处:网络
I\'m porting a C++ application from Unix and the original developer created several files with main() functions, then use Makefile to choose which main() to u开发者_JAVA百科se.

I'm porting a C++ application from Unix and the original developer created several files with main() functions, then use Makefile to choose which main() to u开发者_JAVA百科se.

How do choose which file contains the main() function in Visual C++ 2010?

Currently, when I compile I get a linker error due to duplicate main() symbols.

The only thing I can think of is macro conditional.

Any other ideas?


Multiple main functions mean that the original code does not create a single executable, but rather a set of them. You should figure out what parts belong to each one of the executables (read the Makefile) and then create different projects inside the solution one for each one of the executables (do the same for the libs). Then you can use the IDE to select which executable you want to compile/run.


in the Configuration Properties for each source file (right-click in Solution Explorer) you can select 'Excluded From Build'. As this is a per-configuration setting, you can add some configurations and mutually exclude the files with main(). For instance for configuration 'MainA' you include maina.cpp and exclude mainb.cpp and mainc.cpp, for 'MainB' include mainb.cpp and exclude maina.cpp and mainc.cpp, etc.

Another option would be to have only one main() and select the appropriate source using arguments or a configuration file. Or, maybe the best solution, create one project for each main file and put the common parts in a static or shared library.

0

精彩评论

暂无评论...
验证码 换一张
取 消