如何将 cscope 用于具有 .c 、.cpp 和 .h 文件的项目
How to use cscope for a project which has .c , .cpp and .h files?
我正在做一个需要了解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一起使用的cscope.out文件来浏览代码。希望对您有所帮助!
列出项目中所有C++
文件的便捷方法是使用 ack 工具:一个针对源代码搜索优化的类似 grep 的命令(在某些发行版中,例如 Ubuntu,该工具称为 ack-grep
)。你可以像这样运行它:
ack -f --cpp > cscope.files
输出是所有.cpp
、.h
、.cc
.hpp
文件的路径
只是因为这仍然是最受欢迎的条目。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"
为了覆盖我们的大型代码库,我有一个看起来有点像这样的脚本来构建 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
相关文章:
- 为什么两个不同的未命名名称空间可以共存于一个cpp文件中
- 命名空间中具有.h和.cpp文件的类
- 无法编译 rtmidi 测试 cmidiin.cpp 文件, 非法指令
- C++-试图将函数指针推回到另一个CPP文件中的矢量时出错
- 有充分的理由在h文件中使用include保护而不是cpp文件吗
- 如何在cpp文件之间切换窗口?在Qt中
- 在 .h 文件中的类中声明静态变量和在.cpp文件中声明"global"变量有什么区别
- 我有两个类需要在同一 cpp 文件中相互引用,但第一个类无法识别第二个类类型的对象
- .h 和.cpp文件分离时出错,但仅使用 .h 文件时没有错误.我做错了什么?
- 库标题在标题中不可见,但在 cmake build 下.cpp文件中完全可见.为什么?
- C++ 链接到单独的.cpp文件说"multiple definitions"
- 在 cpp 文件中隐藏采用模板参数引用的方法
- 如何使用 samtools C API 构建一个简单的主.cpp文件
- 包含在.cpp文件中包含在 .h 文件时包含
- C++(.cpp文件和.h文件)拆分代码并添加一个函数,提取 - 这很容易吗?
- 在头文件和 cpp 文件中使用一次 #pragma 时出现结构重定义错误
- 如何使用线程类编译 cpp 文件?
- 使用 Powershell 命令将 cpp 文件的文件夹编译为 GNU 的 g++
- 我应该将外部标头放在 .h 文件还是.cpp文件中?
- 从另一个 cpp 文件更改结构内、映射键内的变量