gpt4 book ai didi

c++ - 获取包含头文件中声明的实体定义的源文件名?

转载 作者:塔克拉玛干 更新时间:2023-11-03 07:50:22 27 4
gpt4 key购买 nike

我有 2 个源文件:test.cpp and func.cpp和 1 个头文件:func.h

这些文件的内容如下:

1。 test.cpp

#include "func.h"

int main() {
...
func();
...
}

2。 func.cpp

#include "func.h"

void func() {
//func() definition
}

=====================

  1. func.h

=====================

#include <iostream>
using namespace std;

void func(); /* func() declaration */

=====================

问题:问题是找出包含头文件中未定义实体定义的源文件名。对于上面提到的例子:我需要找出包含函数“func()”定义的源文件。

已采取但未找到所需结果的方法:我尝试使用“makedepend”和“gcc -MM <source file names>”来获取包含头文件中未定义实体定义的源文件,但它只是给出了一个规则,显示源文件直接或间接包含的头文件.

gcc -M test.cpp func.cpp 的输出如下:

test.o:test.cpp func.h
func.o:func.cpp func.h

我需要得到以下形式的输出:

test.o:test.cpp func.h func.cpp

谁能告诉我解决这个问题的方法。如何获取源文件名,它为我提供了包含头文件中未定义实体的定义提前致谢。

最佳答案

I need the source file defining the undefined entities

使用ctags一次;例如:ctags test.cpp func.cpp func.hctags *.cpp *.h

然后找到func的定义源文件,执行e。 G。 grep '^func\>' 标签:

func    func.cpp        /^void func() {$/;"     f

关于c++ - 获取包含头文件中声明的实体定义的源文件名?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30151408/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com