boost::TIME_UTC(_) with different boost versions - c++

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.

Related

How to upgrade _RICHEDIT_VER (riched20.dll) to version 3 or higher

I am using for a C++ LIbrary WTL10 from Microsoft. If i want to compile it in VS19, i will get an error, that says WTL10 requieres Richedit version 3 or higher.
Here is the code from atlctrls.h
#if (_RICHEDIT_VER < 0x0300)
#error WTL10 requires RichEdit version 3 or higher
#endif
But i got in afxwin.h :
#define _RICHEDIT_VER 0x0210
How can i upgrade it? I never upgraded dlls manually, so i wanted to ask here and i could not find help with google for richedit.
------- Found a solution ------
You have to insert
#undef _RICHEDIT_VER
after
<afxwin.h>
Like this:
#include <afxwin.h> // MFC core and standard components
#undef _RICHEDIT_VER
RICHEDIT.H will define_RICHEDIT_VER to the newest version

Can't resolve namespace member 'thread'

I wanted to practice with standard C++ threads instead of UNIX ones, but soon encountered a problem, whenever I write std::thread CLion underlines it with red and says Can't resolve namespace member 'thread'. I checked my CMake file it's set for C++11. I reinstalled the latest version of MinGW (6.3.0) and ticked a box with G++ compiler. I have been told by my friend that he uses Cygwin and everything works. But is it still possible to make it work with MinGW?
#include <iostream>
#include <thread>
#define BUFFER_SIZE 3
#define PROD_NUM 3
#define CONS_NUM 2
void produce(){
//production
}
void consume(){
//consumption
}
int main() {
std::cout << "Hello, World!" << std::endl;
int i,j;
std::thread producer(produce);
std::thread consumer (consume);
return 0;
}
The code itself has literally nothing
EDIT
in thread library there is
#pragma GCC system_header
#if __cplusplus < 201103L
# include <bits/c++0x_warning.h>
#else
#include <chrono>
#include <functional>
#include <memory>
#include <cerrno>
#include <bits/functexcept.h>
#include <bits/functional_hash.h>
#include <bits/gthr.h>
#if defined(_GLIBCXX_HAS_GTHREADS) && defined(_GLIBCXX_USE_C99_STDINT_TR1)
namespace std _GLIBCXX_VISIBILITY(default)
{
_GLIBCXX_BEGIN_NAMESPACE_VERSION
/**
* #defgroup threads Threads
* #ingroup concurrency
*
* Classes for thread support.
* #{
*/
/// thread
class thread
{
public:
// Abstract base class for types that wrap arbitrary functors to be
// invoked in the new thread of execution.
struct _State
{
virtual ~_State();
virtual void _M_run() = 0;
};
can you make sure if the library is available in the CLion toolchain? For example Cygwin does have the include.
CLion shows things red when it can't link codes with the library.
It is possibly a host environment variable error. Make sure your CMakeLists.txt is working and your environment variables, standard library linkage is correct as well as your compiler setup.
Compiler version and and standard libraries compatible. (e.g. you are using a cross-compiler (RasPi, Android) but environment vars shows host library etc. will make it fail)
Check this relevant post, it may help.
C++11 std::threads vs posix threads
Ok, so I finally solved the problem. I installed Cygwin and in CLion Settings I manually linked C/C++ compilers (for some reason CLion was unable to auto-detect them). Cleared all and re-indexed the project. Now it shows no errors and code compiles.
Regarding MinGW, I read on cplusplus.com some posts regarding the issue but they were about previous versions of MinGW and it was said that they finally fixed it, however I tell: No, they didn't. Here there is a nice repository and its README file suggests that thread of win32 rely on gthreads, however i found gthread file in my libraries everything seemed ok... so still need to investigate the issue. Write your ideas and experience here if you know more.
As for now solution is Cygwin, use it instead of MinGW.
P.S. Thanks #KillzoneKid for links

How to selectively include boost headers depending on boost version

This change in Boost caused some header file locations to change: https://github.com/boostorg/property_tree/commit/ea940990691de91e9b22255d9b450fcdac237646
I am working on a codebase where some users build with an older version of boost, with the old header locations, e.g. #include <boost/property_tree/detail/json_parser_error.hpp> instead of the newer #include <boost/property_tree/json_parser/error.hpp>. I want to retain compatibility with both older (pre-1.61) and newer boosts.
Is there a way to instruct the compiler to check for the boost version and use the new header include if the version >= 1.61?
I think you are looking for BOOST_VERSION preprocessor. It is defined in boost\version.hpp
// Caution, this is the only boost header that is guarenteed
// to change with every boost release, including this header
// will cause a recompile every time a new boost version is
// released.
//
// BOOST_VERSION % 100 is the patch level
// BOOST_VERSION / 100 % 1000 is the minor version
// BOOST_VERSION / 100000 is the major version
Simple usage would be:
#if BOOST_VERSION >= 106100
#include <this.hpp>
#else
#include <that.hpp>
#endif

cpp_bin_float not found between boost library

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!

XCode 4.5 'tr1/type_traits' file not found

I use the wxwidget library and I have the following problem:
#if defined(HAVE_TYPE_TRAITS)
#include <type_traits>
#elif defined(HAVE_TR1_TYPE_TRAITS)
#ifdef __VISUALC__
#include <type_traits>
#else
#include <tr1/type_traits>
#endif
#endif
here the #include isn't found. I use the Apple LLVM compiler 4.1. (with the c++11 dialect).
If I switch to the LLVM GCC 4.2 compiler I have no error there, but the main problem is that all the c++11 inclusions won't work.
How can I either use the GCC compiler, but with the c++11 standard or make it that the LLVM can find the ?
any help would be really appreciated.
I'm guessing you have "C++ Standard Library" set to "libc++". If this is the case, you want <type_traits>, not <tr1/type_traits>. libc++ gives you a C++11 library, whereas libstdc++ (which is also the default in Xcode 4.5) gives you a C++03 library with tr1 support.
If you want, you can auto-detect which library you're using with:
#include <ciso646> // detect std::lib
#ifdef _LIBCPP_VERSION
// using libc++
#include <type_traits>
#else
// using libstdc++
#include <tr1/type_traits>
#endif
Or in your case perhaps:
#include <ciso646> // detect std::lib
#ifdef _LIBCPP_VERSION
// using libc++
#define HAVE_TYPE_TRAITS
#else
// using libstdc++
#define HAVE_TR1_TYPE_TRAITS
#endif
This is the command I used to build wxWidgets against libc++ (LLVM C++ Standard Library). Should work on Yosemite and later (at least until Apple breaks everything again):
mkdir build-cocoa-debug
cd build-cocoa-debug
../configure --enable-debug --with-macosx-version-min=10.10
make -j8 #This allows make to use 8 parallel jobs
Slightly modified the code above, to avoid compiler complaints:
Paste the following into strvararg.h just before #ifdefined (HAVE_TYPE_TRAITS)
#include <ciso646> // detect std::lib
#ifdef _LIBCPP_VERSION
// using libc++
#ifndef HAVE_TYPE_TRAITS
#define HAVE_TYPE_TRAITS 1
#endif
#else
// using libstdc++
#ifndef HAVE_TR1_TYPE_TRAITS
#define HAVE_TR1_TYPE_TRAITS 1
#endif
#endif