我一直在尝试使用boost.multiprecision在我的VC2017项目中工作时遇到问题,并且我尝试将最简单的项目作为概念证明:
#include<boost/multiprecision/cpp_int.hpp> int main() { boost::multiprecision::cpp_int val{ 5 }; val *= 5; val *= 5; return val.convert_to<int>(); }
1>------ Build started: Project: Multiprecision Test,Configuration: Debug x64 ------ 1>Multi Main.cpp 1>Unknown compiler version - please run the configure tests and report the results 1>g:\workspacec\solutions\project4x\library\include\boost\utility\compare_pointees.hpp(36): error C2143: Syntax error: missing ',' before '<' 1>g:\workspacec\solutions\project4x\library\include\boost\utility\compare_pointees.hpp(40): note: see reference to class template instantiation 'boost::equal_pointees_t<OptionalPointee>' being compiled 1>g:\workspacec\solutions\project4x\library\include\boost\utility\compare_pointees.hpp(59): error C2143: Syntax error: missing ',' before '<' 1>g:\workspacec\solutions\project4x\library\include\boost\utility\compare_pointees.hpp(63): note: see reference to class template instantiation 'boost::less_pointees_t<OptionalPointee>' being compiled 1>g:\workspacec\solutions\project4x\library\include\boost\numeric\conversion\detail\converter.hpp(453): error C2143: Syntax error: missing ',' before '<' 1>g:\workspacec\solutions\project4x\library\include\boost\numeric\conversion\detail\converter.hpp(467): note: see reference to class template instantiation 'boost::numeric::convdetail::trivial_converter_impl<Traits>' being compiled 1>g:\workspacec\solutions\project4x\library\include\boost\numeric\conversion\detail\converter.hpp(453): error C2518: keyword 'typename' illegal in base class list; ignored 1>g:\workspacec\solutions\project4x\library\include\boost\numeric\conversion\detail\converter.hpp(454): error C2518: keyword 'typename' illegal in base class list; ignored 1>g:\workspacec\solutions\project4x\library\include\boost\numeric\conversion\detail\converter.hpp(474): error C2143: Syntax error: missing ',' before '<' 1>g:\workspacec\solutions\project4x\library\include\boost\numeric\conversion\detail\converter.hpp(497): note: see reference to class template instantiation 'boost::numeric::convdetail::rounding_converter<Traits,RangeChecker,RawConverter,Float2IntRounder>' being compiled 1>g:\workspacec\solutions\project4x\library\include\boost\numeric\conversion\detail\converter.hpp(474): error C2518: keyword 'typename' illegal in base class list; ignored 1>g:\workspacec\solutions\project4x\library\include\boost\numeric\conversion\detail\converter.hpp(475): error C2518: keyword 'typename' illegal in base class list; ignored 1>g:\workspacec\solutions\project4x\library\include\boost\numeric\conversion\detail\converter.hpp(504): error C2143: Syntax error: missing ',' before '<' 1>g:\workspacec\solutions\project4x\library\include\boost\numeric\conversion\detail\converter.hpp(526): note: see reference to class template instantiation 'boost::numeric::convdetail::non_rounding_converter<Traits,RawConverter>' being compiled 1>g:\workspacec\solutions\project4x\library\include\boost\numeric\conversion\detail\converter.hpp(504): error C2518: keyword 'typename' illegal in base class list; ignored 1>g:\workspacec\solutions\project4x\library\include\boost\numeric\conversion\detail\converter.hpp(505): error C2518: keyword 'typename' illegal in base class list; ignored 1>Done building project "Multiprecision Test.vcxproj" -- Failed. ========== Build: 0 succeeded,1 Failed,2 up-to-date,0 skipped ==========
这些是我在最初使用boost.multiprecision的更复杂项目中遇到的完全相同的错误.我在Visual Studio 2015中编译此代码没有任何问题.有谁知道什么是错的,我需要做些什么来解决它?
编辑:
使用boost.asio的项目编译没有问题:
#include<boost/asio.hpp> #include<iostream> int main() { boost::asio::io_service service; for (int i = 0; i < 10; i++) { service.post([i] { std::cout << i << std::endl; }); } service.run(); system("pause"); return 0; }
解决方法
问题是由于boost :: multiprecision中的某些模板使用了std :: unary_function,这个模板自C11以来已被弃用,并从C17的标准中删除.
MSVC 2015中的标准库实现引入了诸如#if _HAS_AUTO_PTR_ETC这样的保护定义.默认情况下,它们在新的switch / std:c 14(默认值)下设置为1,默认情况下在/ std:c latest下设置为0(新的编译器开关自2015 Update 3起可用).
因此,在boost删除对std :: unary_function的依赖关系之前,你必须不使用/ std:c latest(我一直在使用它,因为它出来了)或#define _HAS_AUTO_PTR_ETC 1之后(包括直接或间接)任何标准库头.因此,要么使用编译器选项设置,要么在某些PCH中设置,这是第一个包含在所有翻译单元或类似内容中的PCH.
Stephan T. Lavavej在this blog post中可以找到这些设置的详尽说明,包括控制其他已弃用或已删除功能的其他防护装置. Visual C++ change history 2003 – 2015似乎是MSVC中突破性变化的官方列表,但不幸的是它没有涵盖所有这些细节.一般情况下,扫描Visual C++ Team Blog以获取Stephan的帖子将为您提供有关这些内容的最佳信息.