Botan编译错误VS2015
Botan compile error VS2015
我这里有一个奇怪的情况。我正在尝试将 Botan 加密库与 VS2015 一起使用(因为项目的其他一些部分使用了一些 VS2013 无法编译的繁重的 C++11 代码)并且我得到了一个很长的编译错误(见下文)。
在尝试了各种方法之后,我得出的结论是,即使其中一个 botan 头文件包含在编译的 c++ 源文件中,编译器也会抛出以下错误。现在我在文件中只有一行:
#include <botan/botan.h>
这是我得到的错误:
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.
自从我能够编译和 运行 botan 测试后,我觉得我错过了什么,但我不知道是什么。有没有人有这方面的经验?
(顺便说一句:相同的代码可以用 g++ 4.9 很好地编译)
查看 sources,似乎 Botan::secure_allocator
没有提供形式为
的模板构造函数
template<class U> secure_allocator(const secure_allocator<U>& other);
这是标准要求的。在当前的工作草案中,N4527,相关位在[17.6.3.5] Table 28 - Allocator requirements;第 9 段中的示例也很有用。
因此,我们不能责怪 VC 14 附带的标准库实现需要这个才能编译。我认为错误在牡丹一方。
快速修复是将这样的定义添加到 Botan::secure_allocator
:
template<class U> secure_allocator(const secure_allocator<U>&) BOTAN_NOEXCEPT { }
由于此分配器模板的实例化没有任何非静态数据成员,因此空体应该没问题。但是,我不熟悉这个库,我们在这里讨论密码学,所以,在使用它做任何严肃的事情之前,请与库作者确认更改。
另一种可能的解决方法:
我注意到调用混合类型构造函数的代码似乎仅在启用迭代器调试时才启用,这在调试模式下默认发生。
你试过在发布模式下编译吗?如果我的观察是正确的,您将不会再收到此错误,因为用于迭代器调试的附加机制将被禁用。
要在调试模式下获得相同的行为,请将 _ITERATOR_DEBUG_LEVEL
宏全局设置为 0
。
调试迭代器可用于检测错误(只要性能影响不会影响您),因此我不会将其用作永久修复,但如果您使用它作为临时解决方法可能会有用不想修改botan头文件
这也可以解释为什么您能够编译测试:也许它们是在发布模式下编译的,或者无论如何,结合禁用迭代器调试的设置?
我这里有一个奇怪的情况。我正在尝试将 Botan 加密库与 VS2015 一起使用(因为项目的其他一些部分使用了一些 VS2013 无法编译的繁重的 C++11 代码)并且我得到了一个很长的编译错误(见下文)。
在尝试了各种方法之后,我得出的结论是,即使其中一个 botan 头文件包含在编译的 c++ 源文件中,编译器也会抛出以下错误。现在我在文件中只有一行:
#include <botan/botan.h>
这是我得到的错误:
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.
自从我能够编译和 运行 botan 测试后,我觉得我错过了什么,但我不知道是什么。有没有人有这方面的经验? (顺便说一句:相同的代码可以用 g++ 4.9 很好地编译)
查看 sources,似乎 Botan::secure_allocator
没有提供形式为
template<class U> secure_allocator(const secure_allocator<U>& other);
这是标准要求的。在当前的工作草案中,N4527,相关位在[17.6.3.5] Table 28 - Allocator requirements;第 9 段中的示例也很有用。
因此,我们不能责怪 VC 14 附带的标准库实现需要这个才能编译。我认为错误在牡丹一方。
快速修复是将这样的定义添加到 Botan::secure_allocator
:
template<class U> secure_allocator(const secure_allocator<U>&) BOTAN_NOEXCEPT { }
由于此分配器模板的实例化没有任何非静态数据成员,因此空体应该没问题。但是,我不熟悉这个库,我们在这里讨论密码学,所以,在使用它做任何严肃的事情之前,请与库作者确认更改。
另一种可能的解决方法:
我注意到调用混合类型构造函数的代码似乎仅在启用迭代器调试时才启用,这在调试模式下默认发生。
你试过在发布模式下编译吗?如果我的观察是正确的,您将不会再收到此错误,因为用于迭代器调试的附加机制将被禁用。
要在调试模式下获得相同的行为,请将 _ITERATOR_DEBUG_LEVEL
宏全局设置为 0
。
调试迭代器可用于检测错误(只要性能影响不会影响您),因此我不会将其用作永久修复,但如果您使用它作为临时解决方法可能会有用不想修改botan头文件
这也可以解释为什么您能够编译测试:也许它们是在发布模式下编译的,或者无论如何,结合禁用迭代器调试的设置?