0

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 use std::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.

Chaitanya
  • 177
  • 2
  • 9
  • @Chaitanya They provide a workaround in this other answer: https://stackoverflow.com/a/42041243/260313 – rturrado Jun 13 '21 at 18:11
  • @rturrado that's the same answer that I have linked. I tried that workaround but it is not useful as the feature that is being enabled by `#define _HAS_AUTO_PTR_ETC 1` is removed from C++17 onwards. – Chaitanya Jun 13 '21 at 18:14
  • @S.M. Thanks! But then why does the library states `Any attempt to build with a non C++11 conforming compiler is doomed to failure.`? Are you sure I can use `boost::multipricision` with C++17? – Chaitanya Jun 13 '21 at 18:15
  • 1
    If you show the code, **as plain text**, that's generating the error, we could more easily help you. – Thomas Matthews Jun 13 '21 at 18:25
  • @ThomasMatthews there is no code. All I am doing is downloading boost, unzipping it, placing it in `C:Program Files\boost` and then adding boost root folder in `Additional Include Directories` and then `#include "boost/multiprecision/cpp_int.hpp"` in one of my header files. – Chaitanya Jun 13 '21 at 18:30
  • @S.M. Thanks a lot! I didn't even know we could test it like that :) – Chaitanya Jun 13 '21 at 18:32
  • @S.M. I was just following the guide on boost's website: https://www.boost.org/doc/libs/1_76_0/more/getting_started/windows.html which says `The most reliable way to get a copy of Boost is to download boost_1_76_0.7z or boost_1_76_0.zip and unpack it to install a complete Boost distribution.` and then later at the footer `We recommend downloading boost_1_76_0.7z and using 7-Zip to decompress it.` – Chaitanya Jun 13 '21 at 18:46
  • @S.M. I can install the latest boost version from the link you gave me. However, I am wondering is there any way I can just get the boost::multiprecision only? I don't need anything else from boost library and I would like to avoid the complete installation if possible. I tried to look for it but I am unable to find any resources that could guide me through the process, if you know of any resource that can be useful then I will be very grateful :) – Chaitanya Jun 13 '21 at 18:53
  • @S.M. Installing `boost_1_76_0-msvc-14.2-64` did not solve the problem. Although, not I am able to include `#include "boost/array.hpp"` but for if I do `#include "boost/multiprecision/cpp_int.hpp"` it gives me same error again – Chaitanya Jun 13 '21 at 19:20
  • You may reinstall windows. You don't want to post all true error messages. I am done here. – 273K Jun 13 '21 at 19:44

0 Answers0