【问题标题】:Error compiling in release mode but not in debug mode在发布模式下编译但在调试模式下编译时出错
【发布时间】:2010-10-07 18:48:29
【问题描述】:

当我在调试模式下在 VS 2008 上编译时,一切正常。 当我在发布模式下编译相同的东西时,并非一切正常。据我所知,包含目录是相同的,并且没有额外的预处理器符号。

有什么帮助吗?

1>zlib.cpp 1>C:\Program 文件 (x86)\Microsoft Visual Studio 9.0\VC\include\xutility(419):错误 C2664: 'CryptoPP::AllocatorWithCleanup::AllocatorWithCleanup(const CryptoPP::AllocatorWithCleanup &)' : 无法将参数 1 从 'CryptoPP::AllocatorWithCleanup' 到 '常量 CryptoPP::AllocatorWithCleanup &' 1> 与 1> [ 1>
T=std::_Aux_cont 1> ] 1>
和 1> [ 1>
T=CryptoPP::HuffmanDecoder::CodeInfo 1> ] 1> 和 1> [ 1> T=std::_Aux_cont 1>
] 1> 原因:无法转换 从 'CryptoPP::AllocatorWithCleanup' 到 '常量 CryptoPP::AllocatorWithCleanup' 1> 与 1> [ 1>
T=CryptoPP::HuffmanDecoder::CodeInfo 1> ] 1> 和 1> [ 1> T=std::_Aux_cont 1>
] 1> 没有用户定义的转换 可以执行的操作员 此转换或运算符 不能调用 1> C:\Program 文件 (x86)\Microsoft Visual Studio 9.0\VC\include\xutility(417) : 编译类模板成员时 功能 'std::_Container_base_aux_alloc_real<_alloc>::_Container_base_aux_alloc_real(_Alloc)' 1> 与 1> [ 1>
_Alloc=CryptoPP::AllocatorWithCleanup 1> ] 1> C:\程序文件 (x86)\Microsoft Visual Studio 9.0\VC\include\vector(421) :参见类模板的参考 实例化 'std::_Container_base_aux_alloc_real<_alloc>' 正在编译 1> 与 1>
[ 1>
_Alloc=CryptoPP::AllocatorWithCleanup 1> ] 1> C:\程序文件 (x86)\Microsoft Visual Studio 9.0\VC\include\vector(439) : 参见类模板参考 实例化 'std::_Vector_val<_ty>' 是 编译 1> 与 1> [ 1> _Ty=CryptoPP::HuffmanDecoder::CodeInfo, 1>
_Alloc=CryptoPP::AllocatorWithCleanup 1> ] 1>
C:\myproject\sshlib\zinflate.h(79) : 请参阅对类模板的引用 实例化 'std::vector<_ty>' 正在编译 1> 与 1>
[ 1>
_Ty=CryptoPP::HuffmanDecoder::CodeInfo, 1>
_Ax=CryptoPP::AllocatorWithCleanup 1> ] 1>zinflate.cpp

它最终指向的代码行是:

std::vector<CodeInfo, AllocatorWithCleanup<CodeInfo> > m_codeToValue;

编辑:更多信息:

当我的预处理器包含 NDEBUG 而不是 _DEBUG 时,我得到了这个错误。如果我将发布配置更改为 _DEBUG 而不是它可以编译。为什么?

【问题讨论】:

  • 向量上的分配器参数看起来像一个常量问题。你有更多代码吗?
  • #defining _DEBUG 基本上将构建切换到调试模式。 Microsoft STL 的自定义分配器策略在调试模式下有所不同,不受该 bug 的影响。请参阅下面我的答案中的 Nabble 链接。

标签: c++ compiler-errors crypto++


【解决方案1】:

这是 Visual C++ 编译器中的一个错误。见http://old.nabble.com/-jira--Created:-%28QPID-1458%29-C%2B%2B-common-compile-error-in-VC9-Release-mode-td20469700.html

你可以通过禁用checked iterators来解决它:

#define _SECURE_SCL 0

但请注意:如果您链接到启用 _SECURE_SCL 编译的第三方库,例如boost,内存损坏可能(并且将会)发生。

【讨论】:

  • 我很确定我曾经遇到过这个错误,并且它消失了......也许是在安装了 Visual Studio 服务包之后?我们确实与 boost 合作。
  • 有趣。 @MS SQL Server,你能提供你的编译器的确切版本吗?
  • 这是基本的 VS2008 安装。我希望这是解决方案。我首先尝试通过applygin 2008 SP1 看看它是否有效。安装完成后我会更新票证。
  • 旗帜的作用就像一个魅力,但我确实使用了 boost,但它是单独链接的,所以我有点害怕。 SP1 本身没有解决这个问题。我还有其他选择吗?
  • 尝试从http://update.microsoft.com/ 安装所有更新。重新启动您的机器。启用选中的迭代器。深吸一口气。重建您的解决方案。让我们发布:)
【解决方案2】:

多年后回到 C++,我遇到了类似的错误。原来它与这个错误无关,而一切都与我没有将我的发布配置更新为与调试配置中使用的设置相同的事实有关!所以对于其他新手来说——记住要确保你在所有配置中都有相同的字符集、CLR 支持、包含目录、附加依赖项等等。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-08-10
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多