Crypto++ 在 algparam.h 中给出编译器错误

Crypto++ giving a compiler error in algparam.h

本文关键字:编译器 错误 algparam Crypto++      更新时间:2023-10-16

我在一个相当大的文件中有以下几行:

#include <sha.h>
#include <hex.h>

编译时,会抛出以下编译器错误:

1>d:workapptoolscryptoppalgparam.h(322): error C2061: syntax error : identifier 'buffer'
1>          d:workapptoolscryptoppalgparam.h(321) : while compiling class template member function 'void CryptoPP::AlgorithmParametersTemplate<T>::MoveInto(void *) const'
1>          with
1>          [
1>              T=bool
1>          ]
1>          d:workapptoolscryptoppalgparam.h(329) : see reference to class template instantiation 'CryptoPP::AlgorithmParametersTemplate<T>' being compiled
1>          with
1>          [
1>              T=bool
1>          ]

我很确定我忘记了什么,但我不确定是什么。如果我不包含 hex.h,我没有任何问题,并且我得到了一个 SHA256 哈希就可以了,但是当我包含 hex.h 时,会弹出错误。

编辑

如果有人想知道,来自Crypto++工具包的algparam.h:

void MoveInto(void *buffer) const //<=== line 320
{
    AlgorithmParametersTemplate<T>* p = new(buffer)
    AlgorithmParametersTemplate<T>(*this);
}
CRYPTOPP_DLL_TEMPLATE_CLASS AlgorithmParametersTemplate<bool>; // <== line 329

编辑:删除了不相关的代码

我通过暂时取消定义new来解决问题,它被定义为一些额外调试代码的宏。

#pragma push_macro("new")
#undef new
/* #includes for Crypto++ go here */
#pragma pop_macro("new")

如果要在具有 MFC 支持的 Visual Studio 项目中包括 Crypto++,则此错误可能是由以下行引起的:

#ifdef _DEBUG
#define new DEBUG_NEW
#endif

确保将其删除或注释掉。