[ACCEPTED]-How to let cscope use absolute path in cscope.out file?-cscope

Accepted answer
Score: 16

You can ask vim to interpret the paths in 11 cscope.out relative to the location of the cscope.out 10 file by setting the cscoperelative option. From :help csre:

If 'cscoperelative' is 9 set, then in absence of a prefix given to cscope 8 (prefix is the argument of -P option of 7 cscope), basename of cscope.out location 6 (usually the project root directory) will 5 be used as the prefix to construct an 4 absolute path. The default is off. Note: This 3 option is only effective when cscope (cscopeprg) is initialized 2 without a prefix path (-P).


: set 1 csre
: set nocsre

Score: 12

When importing cscope.out, you can supply 2 the prefix, i.e.

:cscope add /path/to/cscope.out /path/to/src/code

Then your searches will 1 turn up like:

Cscope Tag: foobar
    #   line  filename / context / line
    1     21 /path/to/src/code/foobar_file.c
Score: 4

The cscope tutorial has a very simple workaround for this 23 problem:

11.Try setting the $CSCOPE_DB environment 22 variable to point to a Cscope database you 21 create, so you won't always need to launch 20 Vim in the same directory as the database. This 19 is particularly useful for projects where 18 code is split into multiple subdirectories. Note: for this 17 to work, you should build the database with 16 absolute pathnames: cd to /, and do

find /my/project/dir -name '*.c' -o -name '*.h' > /foo/cscope.files

Then 15 run Cscope in the same directory as the 14 cscope.files file (or use 'cscope -i /foo/cscope.files'), then 13 set and export the $CSCOPE_DB variable, pointing 12 it to the cscope.out file that results):

cd /foo
cscope -b
CSCOPE_DB=/foo/cscope.out; export CSCOPE_DB   

(The 11 last command above is for Bourne/Korn/Bash 10 shells: I've forgotten how to export variables 9 in csh-based shells, since I avoid them 8 like the plague).

You should now be able 7 to run 'vim -t foo' in any directory on 6 your machine and have Vim jump right to 5 the definition of 'foo'. I tend to write 4 little shell scripts (that just define and 3 export CSCOPE_DB) for all my different 2 projects, which lets me switch between them 1 with a simple 'source projectA' command.

Score: 3

You can create your cscope.files using absolute 6 paths to your files, here is my scripts 5 to generate my cscope databases


find $PWD -name '*.[ch]' -exec echo \"{}\" \; | sort -u > cscope.files
cscope -bvq

Then just 4 vim cscope.files and maybe :cs add cscope.out, although 3 my cscope plugin does that automatically. Then 2 I search for the files I am interested in 1 and jump to them with gf.

Score: 1

@Aaron H. is right.

For my configuration 4 I used the cscope_maps.vim plugin and modified 3 the following lines:

  40     " add any cscope database in current directory
  41     if filereadable("/usr/project/cscope.out")
  42         cs add /usr/project/cscope.out /usr/project
  43     " else add the database pointed to by environment variable 
  44     elseif $CSCOPE_DB != ""
  45         cs add $CSCOPE_DB
  46     endif

Where "/usr/project" is 2 the location of the cscope.out file and 1 the absolute path I want to use.

Score: 1

Note: since I am not senior enough to add 15 comments yet: Aaron and Neha's answers were 14 useful to me to learn more about the entire 13 system, but the best and most direct answer 12 to the question is currently in 3rd place 11 and is Shayan's.

The asker was more asking 10 about getting absolute pathnames by cscope, not 9 working around it using (the very capable 8 and powerful) vim.

Note2: There is another 7 way to make a single change in vim and accomplish 6 the same as what Neha did.

:set cscopeprg=cscope -P path_to_relative_base

I like Neha's 5 better, but this way is closer to modifying 4 cscope rather than vim settings, if this 3 is what you want. And this is the only 2 way that allows you to move the cscope db 1 to anywhere.

More Related questions