如何将cscope用于具有.c,.cpp和.h文件的项目?

我正在开发一个需要理解llvm编译器源代码的项目。 要浏览llvm的源代码,我尝试在源的根目录中使用带有以下命令的cscope:

cscope -R *

但它不起作用。 因为主要有.cpp和.h文件,但也有一些.c文件。 那么现在我不知道如何让cscope工作? 有人可以帮忙吗?

您可以使用以下命令从llvm源树的根目录执行所需任务:

touch tags.lst find | grep "\.c$" >> tags.lst find | grep "\.cpp$" >> tags.lst find | grep "\.h$" >> tags.lst cscope -i tags.lst 

它将创建cscope.out文件,该文件与cscope一起用于浏览代码。 希望能帮助到你!

列出项目中所有C++文件的便捷方法是使用ack工具:为源代码搜索优化的类似grep的命令(在某些发行版中,例如Ubuntu,该工具称为ack-grep )。 你可以像这样运行它:

 ack -f --cpp > cscope.files 

输出是所有.cpp.h.cc .hpp文件的路径

为了覆盖我们的大型代码库,我有一个看起来有点像这样的脚本来构建cscope索引。 我改为/的原因是我有源文件的完整文件路径,这使得工作更顺畅。

 cd / find -L /home/adrianc/code -name "*.c" -o -name "*.cc" -o -name "*.h" > /home/adrianc/code/cscope.files cd /home/adrianc/code /usr/local/bin/cscope -b -icscope.files -q -u 

另外值得查看http://cscope.sourceforge.net/cscope_vim_tutorial.html

仅仅因为这仍然是最受欢迎的条目。 stdin thingy可能在此期间添加或不添加,但它使它更优雅:

 find -regex '.*\.\(c\|h\|cpp\|cxx\|hh\|hpp\|hxx\)$' | cscope -i- -b -q 

我在.bashrc中有以下内容,这使事情变得更容易。 运行cscope_build()生成数据库,使用cscope启动cscope工具。

 # Use vim to edit files export CSCOPE_EDITOR=`which vim` # Generate cscope database function cscope_build() { # Generate a list of all source files starting from the current directory # The -o means logical or find . -name "*.c" -o -name "*.cc" -o -name "*.cpp" -o -name "*.h" -o -name "*.hh" -o -name "*.hpp" > cscope.files # -q build fast but larger database # -R search symbols recursively # -b build the database only, don't fire cscope # -i file that contains list of file paths to be processed # This will generate a few cscope.* files cscope -q -R -b -i cscope.files # Temporary files, remove them # rm -f cscope.files cscope.in.out cscope.po.out echo "The cscope database is generated" } # -d don't build database, use kscope_generate explicitly alias cscope="cscope -d"