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

7 c c++ llvm cscope

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

cscope -R*

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

leo*_*dus 10

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

touch tags.lst
find | grep "\.c$" >> tags.lst
find | grep "\.cpp$" >> tags.lst
find | grep "\.h$" >> tags.lst
cscope -i tags.lst
Run Code Online (Sandbox Code Playgroud)

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

  • 做3批`find | grep`有点浪费.你可以很好地使用`egrep`或`grep -E`和一个`find`:`find.-type f -print | grep -E'\.(c(pp)?| h)$'> cscope.files`. (10认同)
  • `cscope -R'`或`cscope $(找-iregex'.+ \.[chp] +')` (5认同)
  • 是的你是对的.实际上我写它是为了让事情易于理解.但无论如何,这不是明智之举. (3认同)

Jan*_*bel 7

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

ack -f --cpp > cscope.files
Run Code Online (Sandbox Code Playgroud)

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

  • 只为你这样懒惰的用户:'sudo apt-get install ack'让我:'ack - 汉字代码转换器',不是同一个实用程序.阅读http://beyondgrep.com/install/页面20秒,我发现它是'sudo apt-get install ack-grep' (3认同)

Val*_*lus 5

我的 .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"
Run Code Online (Sandbox Code Playgroud)