Most of the time, you'll want to ship your finished applications in the smallest, most efficient form possible. The article Optimizing your code - Removing debug data from compiled executable describes how to use TDSTRIP to remove symbolic debugging information from a compiled application. However, if you always let the compiler embed debugging data in your application, the compiler may organize your code in a way that helps with debugging but increases the size of your finished application.
Instead, you should always build your shipping executable files without debugging data. In this article, we'll describe the command-line settings that determine whether the compiler will add debug information to the executable file. Then, we'll work through an example in which we'll demonstrate compiling an executable file with and without the debugging options. We'll also examine how these debugging options affect the executable file's size.
When you run the Borland C++ Command-line Compiler (BCC.EXE), it looks for default compile and link options in the TURBOC.CFG configuration file. First, the compiler looks for TURBOC.CFG in the current directory. Then, if it doesn't find a configuration file, the compiler will use the default TURBOC.CFG file from the startup directory (usually \BORLANDC\BIN).
To create an executable file that you can later debug, you have to pass the appropriate debug option parameters to the command-line compiler. You can either pass these parameters directly from the command line, or you can add them to the configuration file.
The -v parameter tells the compiler to add debugging
information to any object files that appear after the parameter.
For example, the line
bcc -c file1.c -v file2.c
tells the compiler to process FILE1.C without adding debug information and then process FILE2.C and add debug information to the file FILE2.OBJ.
The -c parameter tells the compiler to stop after it
creates the object files. If you replace the -c parameter
with -e and an executable filename, as in the statement
bcc -eTEST.EXE file1.c -v file2.c
the compiler will pass the -v parameter on to the linker. When the linker sees the -v parameter as a command-line option, it will copy the debug information from the object file for FILE2.C into the executable file TEST.EXE.
Since most of the compile sessions for a given project occur during
the debugging phase, we'll go ahead and add these options
to the default configuration file. Then, when we compile a program,
we can simply enter
bcc -c file1.c file2.c
and the compiler will automatically add the debug data to all the object files. This way, we won't have to explicitly add the debug parameters to the command line each time we compile.
Once we finish debugging our application, we'll build it without any debugging information. Since we'll only compile our final executable file a few times, we'll go ahead and enter -v- at the command line to compile without the debugging information. Now, let's compile an executable file with all of the debugging information.
To begin, we'll customize the default configuration file. You can use any standard text file editor for this. We'll use the MS-DOS Editor for this example.
First, make \BORLANDC\BIN the current directory. Then, launch
the MS-DOS Editor with the default configuration file by entering
edit turboc.cfg
at the DOS prompt. When the MS-DOS Editor opens the configuration
file, move the cursor to the end of the file and enter
-v
as one of the default command-line parameters. Figure A shows a typical configuration file with the debug parameter.
Figure A - You can add default command-line parameters to TURBOC.CFG.
Choose Save from the File menu to save the new configuration file. Then, choose Exit from the File menu to return to the DOS prompt.
Next, make \BORLANDC\EXAMPLES the current directory. Borland C++
includes VCIRC.PRJ as an example project to compile from the Integrated
Development Environment. To compile a debuggable version of this
application from the command line, enter
bcc -1 -eVCIRC.EXE vcirc.cpp vpoint.cpp  graphics.lib
at the DOS prompt. The -1 parameter tells the compiler to use 80186/80286 instructions in the object files. Figure B shows the output from the command-line compiler for this executable file.
FIGURE B You can use the command-line compiler to build any of the example projects.
Borland C++ Version 3.1 Copyright (c) 1992 Borland International vcirc.cpp: vpoint.cpp: Turbo Link Version 5.1 Copyright (c) 1992 Borland International Available memory 4046636
When the compile and link process is complete, enter
dir vcirc.exe
at the DOS prompt and note the final executable file's size in bytes. Now, let's see what happens to the executable file's size when we compile without the debug information.
As we mentioned earlier, you can exclude all debug information
from the executable file by passing the -v- parameter
to the command-line compiler. This works even when the debug parameter
is part of the configuration file. To build a final (no debug)
version of VCIRC.EXE, enter
bcc -1 -v- -eVCIRC.EXE vcirc.cpp vpoint.cpp  graphics.lib
at the DOS prompt.
When the compile and link process is complete, again enter
dir vcirc.exe
at the DOS prompt. Table A, compares the sizes of the VCIRC.EXE executable file with and without debug information.
TABLE A: Compiling with debug information can substantially increase an application's size.
Executable File Size (in bytes) | ||
Compiled with debug | Compiled without debug | |
35,230 | 26,604 |
In this article, we showed you how to compile your applications
with and without embedded debug information. If you always build
your final executables without including debug data, the compiler
will arrange the code in the most size- and space-efficient manner
possible.
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.