首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Botan编译错误VS2015

Botan编译错误VS2015
EN

Stack Overflow用户
提问于 2015-08-04 07:08:14
回答 1查看 1.4K关注 0票数 4

我这里有个奇怪的情况。我试图在VS2015中使用Botan密码库(因为项目的其他部分使用了一些VS2013无法编译的繁重的C++11代码),而且我得到了一个相当长的编译错误(参见下面)。

在尝试了各种方法之后,我得出了这样的结论:即使编译的c++源文件中包含了僵尸头,编译器也会抛出下面的错误。现在,我在文件中有一行:

代码语言:javascript
复制
#include <botan/botan.h>

这就是我遇到的错误:

代码语言:javascript
复制
    C:\Program Files\Microsoft Visual Studio 14.0\VC\INCLUDE\xmemory0(876): error C2664: 'Botan::secure_allocator<_Newfirst>::secure_allocator(const Botan::secure_allocator<_Newfirst> &)': cannot convert
argument 1 from 'std::_Wrap_alloc<Botan::secure_allocator<Botan::byte>>' to 'const Botan::secure_allocator<_Newfirst> &'
        with
        [
            _Newfirst=std::_Container_proxy
        ]
C:\Program Files\Microsoft Visual Studio 14.0\VC\INCLUDE\xmemory0(876): note: Reason: cannot convert from 'std::_Wrap_alloc<Botan::secure_allocator<Botan::byte>>' to 'const Botan::secure_allocator<_Ne
wfirst>'
        with
        [
            _Newfirst=std::_Container_proxy
        ]
C:\Program Files\Microsoft Visual Studio 14.0\VC\INCLUDE\xmemory0(876): note: No user-defined-conversion operator available that can perform this conversion, or the operator cannot be called
C:\Program Files\Microsoft Visual Studio 14.0\VC\INCLUDE\vector(587): note: see reference to function template instantiation 'std::_Wrap_alloc<Botan::secure_allocator<_Newfirst>>::_Wrap_alloc<std::_Wr
ap_alloc<Botan::secure_allocator<Botan::byte>>>(_Other &) noexcept' being compiled
        with
        [
            _Newfirst=std::_Container_proxy,
            _Other=std::_Wrap_alloc<Botan::secure_allocator<Botan::byte>>
        ]
C:\Program Files\Microsoft Visual Studio 14.0\VC\INCLUDE\vector(587): note: see reference to function template instantiation 'std::_Wrap_alloc<Botan::secure_allocator<_Newfirst>>::_Wrap_alloc<std::_Wr
ap_alloc<Botan::secure_allocator<Botan::byte>>>(_Other &) noexcept' being compiled
        with
        [
            _Newfirst=std::_Container_proxy,
            _Other=std::_Wrap_alloc<Botan::secure_allocator<Botan::byte>>
        ]
C:\Program Files\Microsoft Visual Studio 14.0\VC\INCLUDE\vector(585): note: while compiling class template member function 'void std::_Vector_alloc<std::_Vec_base_types<_Ty,_Alloc>>::_Free_proxy(void)
'
        with
        [
            _Ty=Botan::byte,
            _Alloc=Botan::secure_allocator<Botan::byte>
        ]
C:\Program Files\Microsoft Visual Studio 14.0\VC\INCLUDE\vector(552): note: see reference to function template instantiation 'void std::_Vector_alloc<std::_Vec_base_types<_Ty,_Alloc>>::_Free_proxy(voi
d)' being compiled
        with
        [
            _Ty=Botan::byte,
            _Alloc=Botan::secure_allocator<Botan::byte>
        ]
C:\Program Files\Microsoft Visual Studio 14.0\VC\INCLUDE\vector(679): note: see reference to class template instantiation 'std::_Vector_alloc<std::_Vec_base_types<_Ty,_Alloc>>' being compiled
        with
        [
            _Ty=Botan::byte,
            _Alloc=Botan::secure_allocator<Botan::byte>
        ]
c:\Botan\include\botan-1.11\botan/rng.h(43): note: see reference to class template instantiation 'std::vector<Botan::byte,Botan::secure_allocator<Botan::byte>>' being compiled
NMAKE : fatal error U1077: 'C:\PROGRA~1\MICROS~3.0\VC\bin\cl.exe' : return code '0x2'
Stop.
NMAKE : fatal error U1077: '"C:\Program Files\Microsoft Visual Studio 14.0\VC\BIN\nmake.exe"' : return code '0x2'
Stop.
NMAKE : fatal error U1077: '"C:\Program Files\Microsoft Visual Studio 14.0\VC\BIN\nmake.exe"' : return code '0x2'
Stop.

由于我能够编译和运行僵尸测试,我有一种感觉,我错过了一些东西,但我不知道是什么。有人有这方面的经验吗?(顺便说一句:相同的代码可以很好地用g++ 4.9编译)

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2015-08-04 09:36:38

查看资料来源Botan::secure_allocator似乎没有提供表单的模板构造函数

代码语言:javascript
复制
template<class U> secure_allocator(const secure_allocator<U>& other);

这是标准所要求的。在目前的工作草案N4527中,相关的双边投资条约载于17.6.3.5表28 -分配器要求;第9段中的例子也很有用。

因此,我们不能责怪VC 14附带的标准库实现需要这样做才能编译。在我看来,这个错误是站在博坦这边的。

一个快速的解决方法是将这样的定义添加到Botan::secure_allocator

代码语言:javascript
复制
template<class U> secure_allocator(const secure_allocator<U>&) BOTAN_NOEXCEPT { }

因为这个分配器模板的实例化没有任何非静态数据成员,所以空体应该是可以的。但是,我不熟悉这个库,我们在这里讨论的是密码学,所以,在使用它来做任何严肃的事情之前,请与库作者确认更改。

另一种可能的解决办法是:

我注意到,调用混合类型构造函数的代码似乎只有在启用迭代器调试时才启用,默认情况下,这种情况发生在Debug模式中。

你试过在发布模式下编译吗?如果我的观察是正确的,您将不再得到这个错误,因为用于迭代器调试的附加机制将被禁用。

要在调试模式下获得相同的行为,请将_ITERATOR_DEBUG_LEVEL宏设置为0全局。

调试迭代器对于检测错误很有用(只要性能不影响您),所以我不会使用它作为永久修复,但是如果您不想修改Botan头文件,它可以作为临时解决方案。

这也可以解释为什么您能够编译这些测试:也许它们是在发布模式下编译的,或者,无论如何,使用禁用迭代器调试的设置组合在一起?

票数 6
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/31802806

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档