wp2
wp2

Reputation: 1421

Why each c++ project can only build one executable in visual studio?

Is this visual studio specific or all c++ projects behave this way?

Why??

Upvotes: 0

Views: 452

Answers (4)

Martin Ba
Martin Ba

Reputation: 38766

Because in Visual Studio, the term "project" is defined to be the entity (a set of source files) that emits one binary build artifact (dll / exe / static lib / ...).

Note: A project actually can and does generate different binary artifacts (debug vs. release vs. configuration-xy) but normally all from the same set of source files.

If you want to create more than one executable with a varying but overlapping set of source files, then you should split your solution into multiple projects:

  • The overlapping set(s) of source files go into a project(s) generating a static lib(s) (or DLL if you want)
  • The unique set of source files for each executable go into a separate project for each executable and each executable project links to the static-lib project(s).

Upvotes: 1

Tony Delroy
Tony Delroy

Reputation: 106068

C++ generally has no concept of a solution... the Standard only defines what happens in the context of each translation unit (some of which relates to creating objects that can link properly). The most widespread project build tool used for development is probably still make, which allows multiple targets to be defined.

Upvotes: 1

ChrisW
ChrisW

Reputation: 56083

If you want to build more than one executable, then you can have several projects defined in the same "solution" file.

Upvotes: 6

Phong
Phong

Reputation: 6768

How would you make the difference between the 2 different main of the two program ? It is quite complicated to know which source is for the programe 1 and which source is for the program 2. Thus, you need 2 different projects for 2 executable.

If you have shared source code between your two project, you can have a library (in a different project ^^).

Upvotes: 1

Related Questions