The creation of a symbol file is demonstrated with the following simple example.
Source files
An executable is produced from the following three source files, of which one is a
header file that is included by the two other c files.
func.c
A simple function is defined in func.c
:
#include "func.h"
int func(int arg_one, int arg_two) {
return arg_one + arg_two;
}
main.c
main.c
contains the
main()
function and uses
func()
to calculate a result.
#include <stdio.h>
#include "func.h"
int main(int argc, char* argv[]) {
if (argc < 2) {
printf("%s arg-1 arg-2\n", argv[0]);
return;
}
int result = func(atoi(argv[1]), atoi(argv[2]));
printf("%s + %s = %d\n", argv[1], argv[2], result);
}
func.h
The headerfile that declares func
:
int func(int arg_one, int arg_two);
Compiling the sources
On the command line, the sources can be compiled into object files and symbol files like so:
cl /Zi /c main.c /Fd:main.pdb
cl /Zi /c func.c /Fd:func.pdb
After creating the object files, they can be linked like so
link main.obj func.obj /out:prog.exe /DEBUG
Apparently, the
/DEBUG
option is essential for the linker to produce the symbol files.
The .pdb
files that were created in the compilation step don't need to given as arguments to the linker because their name is also found in the object file.