确定c++中包含符号的来源

Determining the source of an included symbol in C++

本文关键字:符号 包含 c++ 确定      更新时间:2023-10-16

我目前正在做一个禁止包含c++标准库的项目。我们正在使用的编译文件之一列出了以下符号:_Xran__Q2_3std12_String_baseCFv

我相信这与标准库字符串有关。我这样想错了吗?如果没有,有没有人知道一种有效的方法来追踪这个符号被包含的点?粗略地搜索代码库不会发现任何明显的东西。

这似乎不是VC的混淆,它总是以问号开头。

但是,它符合g++的mangling方案,正如运行

所建议的那样
$ c++filt  --format=gnu "_Xran__Q2_3std12_String_baseCFv"
std::_String_base::_Xran( const(void))

奇怪的是,_Xran似乎是VC对std::string实现的一部分。

无论如何,你正在寻找的标题可能是#include <string>

EDIT:作为c++filt输出的结果-你确定它是在vc++中编译的吗?

如果string.h确实包含在某个地方,您可以找到在哪里:

在下一行#include指令之后放置以下代码:

using namespace std;class string;struct{void hxtestfunc(void){typedef string hxtesttype;}};

编译时,只有当string.h(或任何直接或间接包含string.h的文件)在之前的某个地方包含时,才会生成"ambiguous symbol"错误。

因此,第一个报告的"ambiguous symbol"错误将引导您到关键包含之后的行。

在Visual c++中,你可以使用正则表达式:

代替

" {# include。*}"

"nusing namespace std;class string;struct{void htestfunc(void){typedef string htesttype;}};"