Last update March 7, 2012

Reference For Tools /

Download cscope from either the official website, or if you're using Windows get it from here.

Cscope can be used directly by calling it from a shell, but it's much easier to use it from an editor's interface, which is described in this guide (Vim is an example of an editor that comes with built-in support for Cscope).

The necessary steps for building a cscope database are:

  • 1. Collect a list of filenames for the database and store the list into the file cscope.files. You should be careful not to add any non-sourcecode or version control files to the list. The source files do not need to have the full path listed in the output file.
  • 2. Call Cscope from within the same directory as the file cscope.files to build the database.
  • 3. Use the newly built cscope.out database file in your favourite editor/IDE that supports Cscope.
Detailed instructions (These are specific to Windows and Vim, but they should be easily adaptable to other platforms and tools):
  • 1. Use a good find tool to get a list of source files and output the list to a file called cscope.files. ack is a good tool for this.
      • Quick ack install guide for Windows: Get and install Strawberry Perl, add the executables to the PATH, and then issue this call in a command-prompt:
      • perl -MCPAN -e "CPAN::Shell->force(qw(install App::Ack));"
    • The ack command to get all the C++ and D files recursively from the current directory is:
      • ack -f --type-set D=.d,.di -D --cpp > cscope.files (Read the ack documentation for details on these arguments)
  • 2. Build the Cscope database by calling:
    • cscope -b in the same directory as cscope.files.
  • 3. Use the instructions that come with your editor/IDE to add and link to the Cscope database. In Vim you can use this command:
    • :cscope add %:p:h - Note that "%:p:h" expands to the current working directory in Vim. Otherwise replace this with the location of the file cscope.out, or the directory it resides in.
Automating usage of Cscope in Vim (Windows-specific, but adaptable to other platforms)

I've installed the Shell.vim plugin: , which enables calling external shell commands without blocking Vim and without popping up of the command-prompt. I have these lines in my _vimrc file: . I also have a batch file buildcscopetags.bat in my PATH with the line:

  • ack -f --type-set D=.d,.di -D --cpp > cscope.files && cscope -b
Now all I have to do is use ,t in a Vim buffer and I will have a newly built and added cscope database with all the C++ and D files found in the directory (and any subdirectories) of the current file. I can place my cursor over a function name and use Ctrl-] to find all the functions that call the function under the cursor. There are many other find commands that can be automated.

Use :h cscope in Vim for additional details on using Cscope. You might also want to try some Vim front-ends that work with Cscope (and Ctags): Vim Cscope Search

FrontPage | News | TestPage | MessageBoard | Search | Contributors | Folders | Index | Help | Preferences | Edit

Edit text of this page (date of last change: March 7, 2012 20:41 (diff))