cpp_bin_float not found between boost library - c++

I'm using boost library to handle big numbers.
#include <iostream>
#include <boost/multiprecision/cpp_bin_float.hpp>
#include <boost/multiprecision/number.hpp>
namespace mp=boost::multiprecision;
using namespace std;
int main()
{
typedef mp::number<mp::backends::cpp_bin_float<2000> > cpp_bin_float227;
cpp_bin_float227 b = 998;
std::cout << std::numeric_limits<cpp_bin_float227>::digits << std::endl;
cout<<std::setprecision(std::numeric_limits<cpp_bin_float227>::max_digits10)<<pow(b,9999)<<endl;
}
But I got this error at compile-time:
fatal error: boost/multiprecision/cpp_bin_float.hpp: No such file or directory
#include <boost/multiprecision/cpp_bin_float.hpp>
If I use cpp_dec_float instead of cpp_bin_float it works fine.
Why is the library not found and how to fix it?
(I'm using c++11 compiler, in Ubuntu)
SOLUTION:
The problem was that in answe, namely aold version of boost library.
Minimal version to support cpp_bin_float is 1.58
Remove current version with:
apt-get --purge remove libboost-dev libboost-doc
Later I installed version 1.63 (isn't the latest that is 1.64) following
http://www.linuxfromscratch.org/blfs/view/cvs/general/boost.html

That version of boost doesn't have cpp_bin_float. It's also seriously old.
See it live:
boost 1.54 https://wandbox.org/permlink/7MQy5HR90GB0GbVt
boost 1.55 https://wandbox.org/permlink/nPOH5kDRCq1PUXWl
boost 1.56 https://wandbox.org/permlink/IhClSKBx0k0pSVUe OK!

Related

filesystem namespace problems with C++17

Having troubles accessing the filesystem namespace -
Problem:
"Symbol 'filesystem' could not be resolved"`
Leading Research:
How can I get the list of files in a directory using C or C++? - Stack Overflow
C++17 Filesystem - Codingame
Setup:
GCC/G++: 9.2.0
C++: C++17
Demo:
File Demo
#include <iostream>
#include <filesystem>
using namespace std;
namespace fs = std::filesystem;
int main(void) {
return 0;
}
I have tried the std::experimental variant to no success. How can I get C++17 & the <filesystem> API working?
Soln Update:
Thank you P Kramer, w/MSYS2 I was able to quickly come to solution.
Procedure:
Get MSYS2 (msys2-x86_64-20210725.exe)
Run the installer (#loc C:\Sw\msys64)
pacman -Syu
pacman -Su
pacman -S --needed base-devel mingw-w64-x86_64-toolchain
Check w/cmd (C:\Sw\msys64\mingw64\bin)
gcc -v (GCC v10.3.0)
Add to path (C:\Sw\msys64\mingw64\bin, C:\Sw\msys64\usr\bin)
Restart Eclipse
Demo compile to confirm C++17 (__cplusplus == 201703L)
Use it!
Final Working Demo
https://gcc.gnu.org/gcc-9/changes.html mentions incomplete filesystem implementation on windows. Goto compiler explorer and compile your sample with gcc 9.2 first. See here : https://godbolt.org/z/q9vTcernn
This will indeed fail, if you change to latest gcc (for windows) everything compiles fine.
So the problem is the compiler version you are using.

redefinition of class when I use calib3d.hpp in opencv

I am working on ubuntu 16.4 in a C++ project and I'm trying to use a function in opencv2/calib3d.hpp but without any success.
I don't have any problem using cv::Point3d for example, but as soon as I add , I get the following error:
/usr/local/include/opencv2/features2d/features2d.hpp:69: error:
redefinition of ‘class cv::KeyPoint’ class CV_EXPORTS_W_SIMPLE
KeyPoint
Here is my code :
#include <iostream>
#include <opencv2/core.hpp>
#include <opencv2/calib3d.hpp>
int main()
{
std::cout << "cv hello"<< std::endl;
return 0;
}
When I use " pkg-config --modversion opencv " to have the version of opencv used I get "3.1.0"
My idea is that I have several version of opencv installed and conflicting.
I am thinking that because in the proposition of completion, when I am adding
#include , I have several equivalent calib3d.hpp propositions.
How can I know if I have multiple version installed ?
Not sure if this is to much effort, but you could specify the OpenCV version with Cmake.
find_package(OpenCV 3.2 REQUIRED PATHS "/path/to/OCV3.2/install/dir/")
Check this answer from #gabriel-devillers:
https://stackoverflow.com/a/45752688/10889595

OpenCV on C++/Namespace issue?

I am new to C++ so I get some trouble to use openCV on my C++ project. I'm using Xcode as an IDE.
So I used brew to install opencv using the two command lines:
brew install opencv3 --with-ffmpeg --with-tbb --with-contrib
brew reinstall opencv3 --HEAD --with-python3 --with-ffmpeg --with-tbb --with-contrib
I checked the path to add to my project to load the library using recursivity, so I added on Xcode the path for header path and library:
/usr/local/Cellar/**
I also tried to install it another way, but still got the same issue:
brew install opencv
And adding the path to:
/usr/local/include/**
Everything seems to work since the library is detected, but import is not working because I got namespace errors in the openCV files, for instance:
No type named 'unique_ptr' in namespace 'std'
No member named 'allocator_traits' in namespace 'std'; did you mean 'allocator_arg_t'?
I checked on the internet and maybe it should be due to the the C++ language dialect or standard library, but I use GNU ++ 14 and libc++ . From what I found it should be working in that config, but I still got the issues. Do you have any ideas ?
EDIT: I don't even try to use it yet, I just used the include and print an hello:
#include <iostream>
#include "cv.h"
int main(int argc, char *argv[]){
std::cout<<"hello";
}
I also tried cv.hpp instead of cv.h, still not working
Thanks a lot !
I don't think you are using the correct #include paths, if you look at the OpenCV Example, you need the following for OpenCV 3.0 to open an image:
#include <opencv2/core/core.hpp>
#include <opencv2/imgcodecs.hpp>
#include <opencv2/highgui/highgui.hpp>
None of these are like the headers that you have, which are likely for older versions.
This tutorial looks like a very sensible one to get up and running with xcode, and the example at the bottom looks like a better start

boost::TIME_UTC(_) with different boost versions

I just upgraded my project on Windows from boost 1.46 to the current boost 1.52. We have some usages of boost::TIME_UTC which I changed to boost::TIME_UTC_ according to https://svn.boost.org/trac/boost/ticket/6940.
However, we also build the source on some linux machines with boost 1.49 which doesn't know the boost::TIME_UTC_. Is there any suggested way to use boost 1.49 and 1.52 in parallel with TIME_UTC?
Change everything to TIME_UTC_. Then use this:
#include <boost/version.hpp>
#if BOOST_VERSION < 105000
#define TIME_UTC_ TIME_UTC
#endif
We use:
#include <boost/version.hpp>
#if BOOST_VERSION < 105000
#include <boost/thread/xtime.hpp>
namespace boost {
enum xtime_compat {
TIME_UTC_=TIME_UTC
};
}
#endif
This way you can use boost::TIME_UTC_, as in 1.50 onwards.
But not for openSuse, because they decided to merge this change back to 1.49.

Boost lib appears to be missing hpp files?

I'm trying to compile a C++ project that requires Boost. I downloaded the latest build from the web site and copied the appropriate files to the appropriate libs folder (I'm using MinGW). When I compile, I'm get this error:
In file included from main.cpp:4:0:
headers.h:59:29: fatal error: boost/foreach.hpp: No such file or directory
compilation terminated.
I can find a working copy of foreach.hpp but I shouldn't have to move code files manually.
Solution
I had copied boost to the wrong folder.
I got this error on Ubuntu 12.10 when trying to use boost with a C++ application without the libraries installed:
el#apollo:~/foo8/33_parse_file$ g++ -o s s.cpp
s.cpp:3:29: fatal error: boost/foreach.hpp: No such file or directory
compilation terminated.
From this code:
#include <iostream>
#include <boost/foreach.hpp>
#include <boost/tokenizer.hpp>
using namespace std;
int main(){
cout << "hi";
}
I'm on Ubuntu 12.10 so I installed Boost like this:
sudo apt-get install libboost-all-dev
Then on recompile, it works and now I can use boost!
#include <iostream>
#include <string>
#include <boost/foreach.hpp>
#include <boost/tokenizer.hpp>
using namespace std;
using namespace boost;
int main(int argc, char** argv)
{
string text = "token test\tstring";
char_separator<char> sep(" \t");
tokenizer<char_separator<char> > tokens(text, sep);
BOOST_FOREACH(string t, tokens)
{
cout << t << "." << endl;
}
}
Prints the three words token, test, string
You should make sure that your include path is set correctly. Assuming you downloaded Boost 1.47.0 your path should contain the location to your Boost installation up to the boost_1_47_0 directory, but leaving out the boost one, e.g.
/path/to/boost/boost_1_47_0
and not
/path/to/boost/boost_1_47_0/boost
On Fedora and Centos yum install -y boost and yum install -y boost-devel