Using Projects with Turbo/Borland C++

Introduction

Most of this information will apply to using projects with other Borland IDEs. However, the brief instructions in this document have been tested with Turbo 4.5 and with Borland 4.52 running under Windows 95 and under Windows NT. If differences between Windows 95/NT and Windows 3.1 develop, I will amend this document to reflect the differences.

Borland 5.0 users I've updated sections of the document for those using Borland 5.0 (I've tested making projects/libraries using Borland 5.02).

Although you may not have thought deeply about it, all programs you've written using Turbo/Borland compilers have linked in code stored in libraries. Libraries are needed for I/O, math, graphics, and so on. Normally the IDE (Integrated Development Environment) takes care of the details of linking in the right libraries for you. When you use AP classes, and other classes that you decide will be useful for students to use (e.g., Dice, Date, etc.) student projects will need to link the code for these classes into the project. You can do this in one of two ways:

  1. Include all the source code (*.cpp files) for all classes used in the project. Class implementations do not have main functions, so you then add a program with a main, that uses the classes. You build your project, then run it. The word build is used rather than compile because there are several files that are compiled to create the executable program. Libraries are linked with the compiled code as well to create the executable.

  2. Create a library of the AP and other class code. Then add this single library to the project in which the program you write (the file containing main) is located. Build the executable and run it.

There are at least two distinct advantages to creating a library. The first is that a student project has only two entries in it (or more if the student herself creates a multi-file project): the apclass library and the student code. The second is that when the code is put in the library, only the code that's needed is linked and added to the executable program. This makes programs smaller.

Creating and Using Projects

In this section we'll discuss the rudiments of creating a new project, adding files to it, compiling and running. This isn't meant to be a complete introduction to projects, there is online help for that, but the online help is scattered and some of the information in this section isn't immediately accessible.

To create a new project follow these steps -- be sure to see the instructions after these if you need to include AP classes, or other non-system classes that you're using.

  1. Borland 5.0

    The option for 'new project' is found under the File menu, there is a submenu labeled New, choose Project there. Proceed as with Borland/Turbo 4.5.

    Borland/Turbo 4.5

    From the Project menu choose New project. When the dialog box pops up, specify EasyWin[.exe] for the Target Type. You do this by clicking on this label. You shouldn't have to change either the Platform or the Target Model. The defaults of Windows 3.x (16) for Platform and Large for Target Model will work fine (these are the defaults on my machine).

    To specify the name of the project, either use the topmost text field to type the complete path-name of the project, or use the Browse button to navigate among disks and directories, then type the name of the project in the browser dialog.

    By convention, projects in Borland/Turbo use .ide as the suffix. You should use this since it will help the browser find your projects.

  2. You'll get a Project window open at the bottom of the IDE after you create the project. There will be the main project node (labeled with [.exe] and three sub-nodes used for the project. The first thing to do is remove the nodes labeled with [.rc] and [.def] (unless you know how to create these, if so please explain to me).

    To remove a node, click on the icon with the right mouse button held down. This will pop up a little menu with several choices. Choose Delete Node and click on Yes when the dialog asks for confirmation.

  3. By default, the name of the .cpp file containing main is the same as the name of the project. If you don't want this, remove the .cpp node. If you do this you'll want to then add a node to the project. You can only add an existing file, so if you want a new file, specify new from the File menu, then save the new file, then add a new node to the project.

    To add a node to the project click on the project node. This is the node at the top of the project window with the [.exe] suffix. Click with the right mouse button, choose add, then navigate to the file you want to add. If you have only one file in the project, you're done and you can now compile and run using the options under the Project menu (compile, make, build) and the Debug menu (run) (or you can use the lightning bolt shortcut).

  4. If your project uses more than one file, e.g., it uses the class apstring defined in apstring.cpp, you'll need to add other source files to the project. Click (right mouse button) on the top, main project node to add additional source files (but see information on libraries below).

    If you've added other source files, or are using include files that are in another directory, you'll need to modify the paths that the IDE uses to find source and header files. Use the Options menu and choose the Project sub-menu. In the section labeled Directories, which should be showing when you invoke the Project sub-menu, you'll see paths for source, include, and libraries. You'll need to modify the Include directories to add the directory in which the ap classes are found. Separate different directories using a semi-colon. On my machine I use the following, you'll need to modify this for your machine (I'm adding the directory c:\apclasses to the include path).

    e:\tcwin45\include;c:\apclasses

    Order matters

    If you want the apclasses directory to be included first, then be sure to put it before the system includes.

  5. If you want to create a style sheet, which you can then attach to any project so that all projects have the same attributes, then you can use the Style Sheet option from the Option menu (although this doesn't seem to always work, see below on how to make all projects inherit the same paths).

    Finally, you can make any project have the same attributes as the last project that was loaded into the IDE. To do this, edit the file tcwin.ini typically found in the Windows subdirectory of your main drive. In the section labeled [Project] add the line

    inherit=1

    then each new project inherits the attributes of the last project. Alternatively, you can also use the same project (this is what I do), and just add a new, main source file.

Creating Libraries

In this section we'll describe briefly how to turn all the ap classes and other classes into a library that can be linked into all of your programs, and your students' programs. If you have a network, you can add new classes to this library and students will automatically link the classes into their projects. This way student projects are kept minimal: typically they have two entries only: a main source file and the apcs library.

In the instructions below you'll learn how to create a library you can use with all student projects.

  1. The first step in creating a library is to specify a new project. When the dialog pops up, specify Static Library (for .exe) [.lib] as the project type. I name the ap library aplib.lib but you can use another name if you want to. You must specify Static rather than Dynamic using the radio buttons that become active when you specify static library as the type of the project --- be sure that you've done this!

    Borland 5.0x users

    You must specify

         win 3.x(16)
    

    under the platform section when creating the static library. This is because the easywin.exe project you'll use is NOT win32, but is a 16bit project. On my machine the default for platform is win32, so be sure to change this or you'll get an error message when your executable/project is compiled/linked.

  2. You'll now add all the source files for the classes you want to include in the library. This includes at least apstring.cpp. You do NOT need to add any of the templated classes, e.g., apvector.cpp or apstack.cpp. Adding these won't do you any good since templated classes must be instantiated before they can be used. For the workshop, I added apstring.cpp, bigint.cpp, clockt.cpp, dice.cpp, prompt.cpp, rando.cpp, strutils.cpp, and systimer.cpp --- but you can add as many .cpp class files to the project as you want to.

    Remember to alter the paths to include files using the Options menu if necessary.

  3. Borland 5.0

    The first step, adding two key files, is not needed in Borland 5.0x, do NOT add these files.

    Borland/Turbo 4.5

    This next step is essential to build a usable library. You must add the following two files to the project.

    • mathwl.lib
    • c0wl.obj
    The letter 'l' in each of these stands for the large programming model. If you're using another model for some reason you'll need to change the 'l' (e.g., to 'm' for medium). I don't know much about this, I do know that using the large model works. These two files are found in the lib subdirectory of the Borland/Turbo distribution. To navigate, use add-node from the project (right click), then find the right drive, and the tcwin45 directory (or bc45, etc.), then the lib subdirectory of this. You'll need to change the browser to allow it to show .lib and .obj files so you can add these to the project.

  4. When you've added all the class files and the two Borland files, you can build the library (Project menu). Hopefully it will build successfully and you'll be ready to go.

After you've created the library you'll want to include it in your project. Add it like any other node. If you need to modify paths to libraries to have the IDE find it, use the Options menu.

From this point on, students only need two entries in their projects: one file that contains a main function, and the library of all class implementations that you created above.


Owen L. Astrachan
Last modified: Sun Sep 6 13:40:03 EDT 1998