I am using Microsoft Visual C++ 2019 with Qt to develop an application. In the code, at certain places, the temporary values go above or below the value that can be handled using a double
. Since long double
is the same as double
in Visual C++, I decided to use Boost Multiprecision library. To test it I included #include "boost/multiprecision/cpp_int.hpp"
, when building my project I get a lot of errors (2233 to be exact), a subset of these errors are:
1>C:\Program Files\boost\boost_1_76_0\boost\concept_check.hpp(810,3): error C2059: syntax error: 'static_cast' (compiling source file plotwidget.cpp)
1>C:\Program Files\boost\boost_1_76_0\boost\concept_check.hpp(810,3): error C2947: expecting '>' to terminate template-parameter-list, found '>' (compiling source file plotwidget.cpp)
1>C:\Program Files\boost\boost_1_76_0\boost\concept_check.hpp(810,3): error C2059: syntax error: ')' (compiling source file plotwidget.cpp)
1>C:\Program Files\boost\boost_1_76_0\boost\concept_check.hpp(810,3): error C2988: unrecognizable template declaration/definition (compiling source file plotwidget.cpp)
1>C:\Program Files\boost\boost_1_76_0\boost\concept_check.hpp(810,3): error C2143: syntax error: missing ';' before '<' (compiling source file plotwidget.cpp)
1>C:\Program Files\boost\boost_1_76_0\boost\concept_check.hpp(810,3): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int (compiling source file plotwidget.cpp)
1>C:\Program Files\boost\boost_1_76_0\boost\concept_check.hpp(810,3): error C2143: syntax error: missing ';' before '{' (compiling source file plotwidget.cpp)
1>C:\Program Files\boost\boost_1_76_0\boost\concept_check.hpp(810,3): error C2447: '{': missing function header (old-style formal list?) (compiling source file plotwidget.cpp)
1>C:\Program Files\boost\boost_1_76_0\boost\concept_check.hpp(811,7): error C2974: 'boost::Mutable_ForwardContainer': invalid template argument for 'C', type expected (compiling source file plotwidget.cpp)
1>C:\Program Files\boost\boost_1_76_0\boost\concept_check.hpp(705): message : see declaration of 'boost::Mutable_ForwardContainer' (compiling source file plotwidget.cpp)
1>C:\Program Files\boost\boost_1_76_0\boost\concept_check.hpp(815,5): error C2988: unrecognizable template declaration/definition (compiling source file plotwidget.cpp)
1>C:\Program Files\boost\boost_1_76_0\boost\concept_check.hpp(815,5): error C2059: syntax error: ',' (compiling source file plotwidget.cpp)
1>C:\Program Files\boost\boost_1_76_0\boost\concept_check.hpp(815,7): error C2974: 'boost::DefaultConstructible': invalid template argument for 'TT', type expected (compiling source file plotwidget.cpp)
1>C:\Program Files\boost\boost_1_76_0\boost\concept_check.hpp(136): message : see declaration of 'boost::DefaultConstructible' (compiling source file plotwidget.cpp)
1>C:\Program Files\boost\boost_1_76_0\boost\concept_check.hpp(810,3): error C2059: syntax error: 'static_cast' (compiling source file plotpaint.cpp)
1>C:\Program Files\boost\boost_1_76_0\boost\concept_check.hpp(810,3): error C2947: expecting '>' to terminate template-parameter-list, found '>' (compiling source file plotpaint.cpp)
1>C:\Program Files\boost\boost_1_76_0\boost\concept_check.hpp(810,3): error C2059: syntax error: ')' (compiling source file plotpaint.cpp)
1>C:\Program Files\boost\boost_1_76_0\boost\concept_check.hpp(816,3): error C2143: syntax error: missing ';' before '{' (compiling source file plotwidget.cpp)
1>C:\Program Files\boost\boost_1_76_0\boost\concept_check.hpp(810,3): error C2988: unrecognizable template declaration/definition (compiling source file plotpaint.cpp)
1>C:\Program Files\boost\boost_1_76_0\boost\concept_check.hpp(816,3): error C2447: '{': missing function header (old-style formal list?) (compiling source file plotwidget.cpp)
1>C:\Program Files\boost\boost_1_76_0\boost\concept_check.hpp(810,3): error C2143: syntax error: missing ';' before '<' (compiling source file plotpaint.cpp)
1>C:\Program Files\boost\boost_1_76_0\boost\concept_check.hpp(810,3): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int (compiling source file plotpaint.cpp)
1>C:\Program Files\boost\boost_1_76_0\boost\concept_check.hpp(810,3): error C2143: syntax error: missing ';' before '{' (compiling source file plotpaint.cpp)
1>C:\Program Files\boost\boost_1_76_0\boost\concept_check.hpp(810,3): error C2447: '{': missing function header (old-style formal list?) (compiling source file plotpaint.cpp)
1>C:\Program Files\boost\boost_1_76_0\boost\concept_check.hpp(811,7): error C2974: 'boost::Mutable_ForwardContainer': invalid template argument for 'C', type expected (compiling source file plotpaint.cpp)
1>C:\Program Files\boost\boost_1_76_0\boost\concept_check.hpp(705): message : see declaration of 'boost::Mutable_ForwardContainer' (compiling source file plotpaint.cpp)
1>C:\Program Files\boost\boost_1_76_0\boost\concept_check.hpp(815,5): error C2988: unrecognizable template declaration/definition (compiling source file plotpaint.cpp)
1>C:\Program Files\boost\boost_1_76_0\boost\concept_check.hpp(815,5): error C2059: syntax error: ',' (compiling source file plotpaint.cpp)
After doing a lot of research, I found this answer which states:
The problem is caused by the fact that some templates in
boost::multiprecision
usestd::unary_function
, which has been deprecated since C++11 and was removed from the standard for C++17.
The README
file in Boost Multiprecision Library states:
ANNOUNCEMENT: Support for C++03 is now removed from this library. Any attempt to build with a non C++11 conforming compiler is doomed to failure.
I am using C++17 and my project is dependent on it, so I guess, I cannot use boost::multiprecision
at all? or is there a way I can force it?
I'm just looking for a type that has higher precision than a double
(preferably 128-bit) and be able to perform elementary functions (+, -, *, /) on it. Is there any way I can achieve that?
EDIT:
Since boost::multipricision
is a header-only library, I am not building boost at all.
EDIT 2: Just to be clear, my entire process is as follows:
-- Download boost
-- Unzip it using 7-Zip and place the boost_1_76_0 in C:\Program Files\boost
-- Add the C:\Program Files\boost\boost_1_76_0 in Additional Include Directories
-- Do #include "boost/multiprecision/cpp_int.hpp"
in only one of my header file.
This is all I am doing that is generating the error. If I comment out the #include "boost/multiprecision/cpp_int.hpp"
from my header file then everything works just fine.