【发布时间】:2014-04-14 23:08:07
【问题描述】:
我正在一个项目中创建一个分析器,我想让它轻松集成到我的项目中。我将 penter 和 pexit 与 /GH /Gh 编译器标志一起使用,因此每次调用或返回函数时都会调用这些函数。现在,基本上我在我的项目中所要做的就是在全局范围内的任何地方复制 penter 和 pexit 函数,并且可以工作,但我想制作一个宏,所以它基本上只是将函数插入其中。我在我的 Profiler.h 文件并将其包含在我的其他项目中。我得到的错误是
error C2598: linkage specification must be at global scope
error C2601: '_pexit' : local function definitions are illegal
error C1075: end of file found before the left brace '{' at 'path/main.cpp' was matched
请注意,“path/main.cpp”是我的项目(非分析器项目)的一条长路径,而 main 是我“调用”宏的地方
这是我的宏,我一定是理解错了。我想它只是在它被“调用”的地方插入函数
#define PENTER \
extern "C" void __declspec(naked) _cdecl _penter(void) \
{ \
_asm push ebp; \
_asm mov ebp, esp; \
_asm pushad; \
Profiler::GetInstance().Enter(); \
_asm popad; \
_asm mov esp, ebp; \
_asm pop ebp; \
_asm ret; \
} \
#define PEXIT \
extern "C" void __declspec(naked) _cdecl _pexit(void) \
{ \
_asm push ebp; \
_asm mov ebp, esp; \
_asm pushad; \
Profiler::GetInstance().Exit(); \
_asm popad; \
_asm mov esp, ebp; \
_asm pop ebp; \
_asm ret; \
} \
感谢您的帮助!
【问题讨论】:
-
查看之前的代码,包括在此之前获得#included 的所有.h 文件。缺少 }。
-
我将宏复制到它们被调用的同一个地方,它可以正常工作,没有问题,没有更改任何其他内容
标签: c++ visual-studio-2012 macros