November, 1994 - Vol. 1 No. 11
Most of the time, when you think of a Borland C++ project file, you probably associate it with the production of a single executable file or Dynamic Link Library (DLL). This file appears in the project window as a named node, as shown in Figure A. Borland calls each first-level node a target, since the resulting executable or DLL is the end goal of the build process.
Figure A - Each executable file or DLL node in the project window is known as a target.
However, you can maintain and build more than one target in any given project. By doing so, you'll be able to keep separate, but related, applications current with each other. In addition, you'll be able to change the build options for all the project's targets simultaneously.
In this article, we'll show you how to add more than one
target to a Borland C++ 4.0 project. First, however, let's
consider some reasons you might want to have more than one target
in a project.
Currently, one of the more popular segments of the software industry is that of application suitesa set of interrelated applications similar to Borland PerfectOffice. Since these types of applications may need to share data or configuration files, you might want to logically associate the source code for each application within the same Borland C++ project.
Similarly, if you need to maintain a custom installation utility for your main application, you may want to include it in the main application's project. Alterations you've made to the main application may change how you need to install the associated files or affect which files you'll need to install.
A third possibility arises if you ship two versions of the same product. An example of this is a User version of a program and an Administrator version of the same program. (The Administrator version may have memory or disk space requirements that are impractical for the User version.)
If you're writing a Windows application, you might at the same time be writing a DLL to implement some of your application's functionality. In such a situation, you'll probably need to change the targets simultaneously.
Finally, you could be supporting both DOS and Windows versions
of the same product. You might want to include both targets in
the same project to aid compatibility testing or feature development.
To add an additional target to an existing Borland C++ project, you'll first need to consider whether the new target will produce OBJ or EXE files that have the same names as those in the existing target.
If both targets will produce files with the same names, you'll need to create a new subdirectory to hold those files. If a source file appears in more than one target node in a project (as a real node, a reference copied node, or as part of a source pool) and you don't specify different destination directories for each target's OBJ files, you may see unpredictable behavior in some of the resulting EXE files.
This can happen because the compiler checks for up-to-date OBJ files for each source file in a given target node. The compiler associates CPP files with the corresponding OBJ files by name. Therefore, if the compiler starts processing the same name a second time, it assumes the OBJ file belongs with that CPP file, it considers the CPP file up-to-date, and it will proceed to link in the OBJ file it compiled for a different target.
If more than one of the targets use the same name, they'll produce EXE files with the same name. If you don't specify a different directory for the EXE files when the targets have the same name, the compiler will simply overwrite the version from the previous target.
After you open the existing project file, you'll use the New Target dialog box to create the appropriate type of target. You can create three types of targets for a project: Standard, AppExpert, or Source Pool.
You'll create a Standard target if you want to produce a DOS or Windows EXE or a DLL. If you want to build an AppExpert Windows application, you'll create an AppExpert target. If you want to build a set of source files you can use in other targets, you'll create a source pool. (To learn more about this, see Borland C++ 4.0 IDE - Dumping code into source pools)
Finally, if you create a new subdirectory for the OBJ and EXE
files the new target will produce, you'll need to change
the Intermediate and Final output directories for that target.
Now, let's try adding a new target to the WHELLO project
that ships with Borland C++ 4.0.
To begin, enter
MD \BC4\EXAMPLES\WINDOWS\WHELLO\BULLSEYE
at a DOS command prompt to create the directory for your new target's files. Even though the new target won't create OBJ or EXE files whose names will conflict with the WHELLO files, you'll place them in this directory to keep them separate.
Now, launch the Borland C++ 4.0 Integrated Development Environment
(IDE). When the IDE's main window appears, choose Open
Project... from the Project menu, enter
\BC4\EXAMPLES\WINDOWS\WHELLO\WHELLO.IDE
in the File Name entry field, and click OK.
When the WHELLO.IDE project window appears, choose New Target... from the Project menu. In the New Target dialog box, enter BULLSEYE in the Target Name entry field and choose Standard from the Target Type combo box, as shown in Figure B.
Figure B - You use the New Target dialog box to name the target and specify its type.
When you're ready to add the new target, click OK. When the Add Target dialog box appears, choose EasyWin [.exe] from the Target Type list box. (This is the same basic dialog box you use when you create a new project.) Click OK.
In the Project window, you'll notice a new node named bullseye
[.exe], as shown in Figure C. This is the new target for
this project.
Figure C - When you add a new target to a project, it appears at the same hierarchical level as the existing target.
Now, click on the icon for bullseye [.exe] in the Project window, double-click on the bullseye [.c] node, and then enter the simple program from Listing A. When you finish entering the code, choose Save from the File menu and then double-click on the editing window's System menu icon to close the window.
Listing A: bullseye.c
#include <stdio.h> int main() { printf("Right on target\n"); return 0; }
To update all the targets in the WHELLO project, choose Make All
from the Project menu. When the Compile Status dialog box appears,
you'll notice that the IDE first builds and links the WHELLO.EXE
file (if necessary) and then builds and links the new BULLSEYE.EXE
file.
There are many types of projects in which you might be maintaining
more than one executable or DLL. By adding targets for these files
to the same project, you can logically associate them to simplify
design, debugging, and maintenance.
Copyright (c) 1996 The Cobb Group, a division of Ziff-Davis Publishing Company. All rights reserved. Reproduction in whole or in part in any form or medium without express written permission of Ziff-Davis Publishing Company is prohibited. The Cobb Group and The Cobb Group logo are trademarks of Ziff-Davis Publishing Company.