Using cscope for first time- command examples

What is cscope anyways? — Its a interactive way to examine a large C project. Browsing through the files manually is a tedious job, cscope comes in handy here. Some basic cscope examples to be used in c projects.You can search for functions, strings or variables declared. Also you can search for specific file names in the entire C project.

This post will come in handy to those who at times forget the cscope cmd to be implemented in there source code to generate the cscope database. Just use ‘cscope -R‘ in the project’s top-level directory to build your Cscope database for the first time, by default Cscope will only parse files with the .c, .h, .y, or .l extensions.

But if you want to include or exclude some specific file extensions you may have to use it using ‘-name‘ switch  with ‘find‘ as below.

Invoking and building cscope database for first time.

find . -name "*.c" -o -name "*.cpp" -o -name "*.h" -o -name "*.hpp" > cscope.files
cscope -b -q -k

After the database is generated use ‘cscope -d‘ to launch the interactive gui to begin with. Use only cscope -d to avoid cscope regenerate the database or again check the project folder this is faster. gui launched here is self explanatory for the search queries available and what needs to be searched for. To exit from cscope interactive prompt, type Ctrl-d.

This entry was posted in C Programming and tagged . Bookmark the permalink.