How to fix duplicate cscope ? is it a better way?
Asked Answered
S

3

13

It is several years I am programming with vim and I used ctags. I am working with a reasonably large C/C++ package and I need to find definition of functions. I usually use grep + ctags. Recently I tried to use cscope instead of ctags and installed it with Vundle. I see the following error for some of my files

E568: duplicate cscope database not added

I searched the web and found this: https://blogs.oracle.com/natarajan/entry/avoiding_duplicate_cscope_database_error It doesn't work.

How can I fix this?

Simdars answered 11/1, 2017 at 21:43 Comment(1)
Your best bet on StackOverflow is to stick to one question per question, rather than adding a second question in a single post. As it is, your second question isn't a good format for StackOverflow anyway; StackOverflow works best with questions where there can be a "correct" answer, and asking for tool recommendations doesn't fit that format. See What topics can I ask about for more info, particularly "Questions asking us to recommend or find...".Schaefer
S
14

Expanding on Artem's answer:

The Vim help for cscopeverbose is as follows:

If 'cscopeverbose' is not set (the default), messages will not be printed indicating success or failure when adding a cscope database. Ideally, you should reset this option in your .vimrc before adding any cscope databases, and after adding them, set it. From then on, when you add more databases within Vim, you will get a (hopefully) useful message should the database fail to be added.

The problem here is that (a) there are multiple scripts attempting to load the cscope.out file and (b) they're not following the best practices of disabling the "verbose" cscope warnings before loading the file then re-enabling it afterwards, as suggested by the help text above.

The full error output should tell you which script is triggering this warning; for me it looked like this:

Error detected while processing /home/me_and/.vim/plugin/cscope_maps.vim:
line   42:
E568: duplicate cscope database not added

The fix was then to edit the ~/.vim/plugin/cscope_maps.vim file to add set nocscopeverbose immediately before the cs add ... lines. My version of this file already had set cscopeverbose immediately after, but if yours doesn't you should add that too.

Schaefer answered 1/3, 2018 at 12:52 Comment(1)
Thanks for your answer - this Q&A helped when I faced the OP's issue today. If you happen to know, I'm curious why this patch is necessary. I encountered this problem for the first time after recently upgrading my fedora core from fc20 -> fc29. I had the same versions of vim and cscope installed before and after the upgrade, so I'm curious why things went from a working to nonworking state.Physiological
M
7

Found the solution which worked for me (here: http://thoughtsolo.blogspot.com/2014/02/cscope-issue-duplicate-cscope-database.html):

Just add this line "set nocscopeverbose " to your ~/.vimrc file.

Middleton answered 22/5, 2017 at 15:37 Comment(0)
A
2

As per the blog, "This error pops up when VIM is already compiled with 'CSCOPE' module and you have also installed "cscopemenu.vim"". I assume that you have a vim executable with has been configured with --enable-cscope option.

Here's what I do:

  • Download cscope source and build it, install the executable in a directory which is available in your PATH
  • Download vim source code and configure it with --enable-cscope, build the source and install the executable
  • Download cscope_maps.vim and place it under $HOME/.vim/plugin directory. This contains cscope settings for vim.
  • Create cscope database out of the source and header files. You may do something like the following

find $PROJECT_HOME -name *.c -o -name "*.cpp" -o -name "*.cc" -o -name "*.h" -o -name "*.hpp" > cscope.files

cscope -qbR -i cscope.files

You can add these commands in an alias and excute the alias every time you want to update your cscope database. These two commands create finally create cscope.out database file.

  • Update .vimrc file to have the following

    if has("cscope") set csprg=<location to cscope executable> set csto=0 cs add <location to cscope.out> endif

I hope after doing these steps you should be able to use cscope with vim easily.

Note that if you are working on multiple projects, you should be able to add appropriate environment variables to enable vim to pick the correct cscope database.

To answer your second question, may I suggest using tagbar. This will list your function names in the current source or header file. You can install it using Vundle. Add the following line to your .vimrc

Plugin 'majutsushi/tagbar'

Add this to your .vimrc to toggle tagbar view

nmap <F4> :TagbarToggle<CR>

Note that F4 is just an example and you may use any binding to do the same.

Autobus answered 7/2, 2017 at 13:37 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.