Search notes:

cl /Zi

cl /Zi creates a symbol file. The name of the symbol file can be specified with the -Fd option.
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;
}
Github repository about-cl, path: /options/Z/i/func.c

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);

}
Github repository about-cl, path: /options/Z/i/main.c

func.h

The headerfile that declares func:
int func(int arg_one, int arg_two);
Github repository about-cl, path: /options/Z/i/func.h

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.

Makefile

Of course, these commands can also be put into a Makefile:
prog.exe: main.obj func.obj
	@link $^ /out:$@ /DEBUG

func.obj: func.c func.h
	@cl -Zi -c $< -Fd:$(basename $@).pdb

main.obj: main.c func.h
	@cl -Zi -c $< -Fd:$(basename $@).pdb

clean:
	@del *.obj *.exe *.pdb *.ilk > nul
Github repository about-cl, path: /options/Z/i/Makefile

TODO

These steps also produces an .ilk file.

See also

The /ZI (uppercase i) also creates a symbol file, but with support for edit and continue.
A symbol file contains line numbers which can be views with dumpbin /linenumbers.
cl options
Turning on/off source line options in Debugging tools for Windows with l+… or l-….

Index