How To Compile VB Programs with Debug Symbols Embedded
Symptoms
The “Compile to Native Code” option introduced in Visual Basic versions 5.0 and 6.0 not only improves performance of Visual Basic programs and components, but also makes it possible to debug them with the Visual C++ debugger.
This article shows you how to compile a Visual Basic program or componentwith embedded debug symbols. By doing so, you simplify the debuggingprocess and avoid the problems associated with mismatched and improperlyplaced symbols.
Resolution
All it takes to compile a Visual Basic program or component with embeddeddebug symbols is a properly set environment variable, LINK. The key is toset it in such a way that Visual Basic inherits the setting when it islaunched. To do this, follow the steps below:
There are several ways to set the LINK environment variable, each of thesemethods is outlined below:
Windows NT or Windows 95/98/MeOpen an MS-DOS Prompt.Navigate to the folder containing Visual Basic.Execute the following command, “set link=/pdb:none” without quotes.Start Visual Basic from the MS-DOS command prompt.
Windows NT OnlyFrom the Control Panel, select the System icon.Select the Environment tab.In the Variable entry, enter “link” without quotes.In the Value entry, enter the following:
/pdb:nonePress Set, then Apply.Start Visual Basic from the MS-DOS command prompt.
Windows 95/98/Me OnlyMake a backup copy of the AutoExec.Bat file.Open the Autoexec.bat file with Notepad.Exe or any text editor.Add the following entry to the AutoExec.Bat file:
set link=/pdb:noneSave the AutoExec.Bat file.Execute the AutoExec.Bat file or reboot the machine.Start Visual Basic.
Once the LINK environment variable is set, a Visual Basic project can becompiled with embedded debug symbols. The following steps describe howto create a test program and compile it with embedded debug symbols:
Step-by-Step ExampleCreate a new Standard EXE project in Visual Basic. Form1 is created bydefault.Add a CommandButton (Command1) to Form1.Add the following code to Form1:
Private Sub Command1_Click()Dim s As Strings = App.EXENamePrint sEnd Sub Select Project1 Properties from the Project menu.Select the Compile tab.Select Compile to Native Code, check Create Symbolic Debug Info, andselect No Optimization.Save the project and create Project1.EXE. Note that the EXE is createdwith embedded debug symbols.
