MinGW standard library missing any.h? - c++

I recently downloaded mingw from http://www.mingw.org/ and installed its c++ compiler and dependencies, which include installing standard library headers. I have also successfully compiled a hello world program, compilation is fine, and common old headers are there and work fine (such as string.h).
However, when I attempted to #include <any>, it threw an error that any.h does not exist. And sure enough, when I look in mingw\include\, there is no any.h (and I see other things missing, such as variant.h).
I've looked through the mingw package manager, and I have the standard library stuff installed, and there's nothing else relevant to install. Does minGW support C++17? If so, how can I get these newer header files? It seems like this should be something really obvious.

You need mingw-w64, which provides more recent GCC versions:
http://mingw-w64.org
You can find a 7.2.0 download here:
http://mingw-w64.org/doku.php/download/mingw-builds

The any feature requires C++17 support, so if your compiler implementation actually does support it, you probably want to specify it on the command line like this:
g++ -std=c++17 a.cpp
Of course, this requires a modern C++ compiler, like that you can get from nuwen.net.

Related

In C++, what is wx.h?

The existing code is calling some sort of wx header file and my DEV C++ compiler just says there's no such file.
Code:
#include<wx/wx.h>
Compiler error:
[Error] wx/wx.h: No such file or directory
So my question is -
What is wx.h
How do I install it in my compiler so that I can use it?
Do I need to change my compiler or DEV C++ would do fine?
What is wx.h
It is the header file of a library. The GitHub project should have some instructions on how to fetch the dependencies and how to install them.
How do I install it in my compiler so that I can use it?
Normally you have to download the dependency, build it (following some instructions), and then you need to use the header in your project and link the library. The exact steps depend on each library and each compiler.
Do I need to change my compiler or DEV C++ would do fine?
In principle, no. Some libraries only work with some compilers, though.
Note that Dev-C++ is not a compiler, it is an IDE that comes with a port of GCC (as far as I know).
It seems that you are using WxWidgets framework but your compiler doesn't know where to find its headers, and apparently also libs which you would face with on a next step.
You, need to add to your compiler flags the output of wx-config --cxxflags. And also to your linker flags the output of wx-config --libs.
Assumption is of course that WxWidgets is installed on your PC

Why doesn't Clang come with standard library headers?

I downloaded Clang 3.6.2 from this website and am trying to set it up with Code::Blocks under Windows. Unfortunately, it fails to compile a simple "hello world" program on the grounds that it doesn't know where iostream is.
Looking through the install folder, it does not appear to include a standard library with it. Why? And how do I get it?
The standard library is NOT part of the compiler itself. It is part of the runtime environment on a particular platform. Sure, some organisations put together a "kit" with all the necessary parts to build an application - there may even be someone that packages a Clang compiler with a suitable runtime.
In general, you should be able to download the Windows SDK and get the relevant header files there - and if you use clang-cl, it should be largely compatible with the MSVC compiler [or provide clang or clang++ with the correct -fms-compatibility or whatever it is called].
Or as suggested in the other answer, use libcxx, but it's not 100% complete for Windows.
They do have a c++ standard library: libcxx.llvm.org. But it's not fully supported on the windows platform.

clang++, boost::spirit and c++11

I'm using clang++ (clang-421.0.60), packaged with Xcode 4.6, and came across an issue with boost::spirit. If I compile without any flags, everything compile fine. If I compile with '-std=c++11', then I get the following error (on including of "boost/spirit/include/qi.hpp"):
In file included from test_spirit11.cpp:1:
In file included from /usr/local/include/boost/spirit/include/qi.hpp:16:
In file included from /usr/local/include/boost/spirit/home/qi.hpp:14:
In file included from /usr/local/include/boost/spirit/home/qi/action.hpp:14:
In file included from /usr/local/include/boost/spirit/home/qi/action/action.hpp:21:
/usr/local/include/boost/spirit/home/support/action_dispatch.hpp:21:10: fatal error:
'type_traits' file not found
#include <type_traits>
The problem is that the default library used (stdlibc++) has type_traits defined as 'tr1/type_traits', whereas boost::spirit expects just 'type_traits'. I can of course fix this problem by doing:
clang++ -std=c++11 -stdlib=libc++ <...>
While I would love to use libc++, the practicality of doing so is difficult (many libraries still use and depend on stdlibc++). Thus, I am forced to not use libc++.
Does anyone have any suggestions on how to deal with this? I really wish that either more library maintainers support libc++ or that Apple provided a newer version of stdlibc++. It's been a major frustration to have access to new c++11 features, but not be able to fully use them due to lack of library support.
The problem is that the default library used (stdlibc++)
It's called libstdc++
has type_traits defined as 'tr1/type_traits', whereas boost::spirit expects just 'type_traits'.
<tr1/type_traits> is not the same thing, it's a different header entirely. boost::spirit wants the C++11 header <type_traits> which is a different header (though they do contain some similar functionality, in different namespaces.)
The problem is probably that you're using the libstdc++ that comes with Apple's ancient version of GCC (4.2) which doesn't support C++11.
If you want to use C++11 you either need to use clang with libc++ or install a newer GCC to get a newer libstdc++. Apple won't provide a newer GCC for licensing reasons, but you can install it yourself and tell Xcode how to find the headers and libs.
If you don't want to use C++11 features in boost you can disable it.
Edit boost clang.hpp to manage features.
For example to disable type_traits file not found error you can add to the end:
#define BOOST_NO_VARIADIC_TEMPLATES

Including C++ 11 headers with Clang / LLVM

I have installed clang and llvm from source, and am trying to compile some C++ code using features of the new standard.
I have found that while for example the use of for ranges e.g. for (i : vector) works fine, I am having trouble (cannot find header file) when I need to import a header e.g. <unordered_set> or <tuple>.
Do I need to use the new libc++ to use these headers, or is there just a simple build change I need to make? At the moment I have just built clang and llvm into a folder in my home directory, and am calling clang++ from there.
See http://clang.llvm.org/get_started.html.
If you intend to work on Clang C++ support, you may need to tell it how to find your C++ standard library headers. If Clang cannot find your system libstdc++ headers, please follow these instructions:
gcc -v -x c++ /dev/null -fsyntax-only to get the path.
Look for the comment "FIXME: temporary hack: hard-coded paths" in clang/lib/Frontend/InitHeaderSearch.cpp and change the lines below to include that path.
While the standard library comes with distributions of your compiler, when you're building it yourself, you still need to build the standard library itself. Some of its components may be header-only, but not all of them are.
So you do need to at least download the library, if not build it. Clang can use GCC's libstdc++, but they also have their libc++ project.

Including boost::filesystem produces linking errors

Ok first off, I am linking to boost_system and boost_filesystem.
My compiler is a custom build of MinGW with GCC 4.3.2
So when I include:
#include "boost/filesystem.hpp"
I get linking errors such as:
..\..\libraries\boost\libs\libboost_system.a(error_code.o):error_code.cpp:
(.text+0xe35)||undefined reference to `_Unwind_Resume'|
..\..\libraries\boost\libs\libboost_system.a(error_code.o):error_code.cpp:
(.eh_frame+0x12)||undefined reference to `__gxx_personality_v0'|
Which after a little searching I found is most commonly when you try to link a C++ program with gcc, the GNU C compiler. But I printed out the exact build command that Code::Blocks is running, and it is definitely linking with g++.
If I comment out this include, everything works fine.
Any ideas? Also, as a side, anyone know of a good place to get windows binaries for boost? The build system is giving me issues, so I'm using some binaries that came with this custom MinGW package
Ok, I found the problem. It's a bit convoluted.
GCC is gradually becoming more IS 14882 compliant in the 4.x branch. As they go on, they are removing deprecated non-standards complaint features.
While 4.1.x seem to only have them deprecated and not removed, 4.3.x seems to actually have them removed. What this means is 4.3.x and greater have some backwards compatibility issues with things compiled in the 3.x branch (which used the deprecated and now removed features)
I was using a mix and match combination of binaries that had been compiled with GCC 3.x, 4.1.x and 4.3.x so no matter which one I used, I got a similar error, because at least one binary I was linking to was incompatible with the compiler I was trying at the moment.
I'm now using GCC 4.1.2 and most of my binaries have been compiled with it. I am still how ever using a few binaries from 3.x, which is why I am not upgrading to 4.3.x just yet.
Hope that was less confusing to read than it was to write...
This seems to be a good post addressing some of the issues as they were with 4.1.x
Windows binaries: www.boost.org - see the "Getting Started" page - but if you're using g++ on MingGW you don't want those. A simple way to understand it is, MingGW is like an operating system inside an operating system so really you're not actually using Windows. The ones you've got are probably right.
Not sure what's going on with your code though, sounds like the lib files aren't linking in properly somehow. Boost names its lib files by themselves so you don't actually name them explicitly, but you have to have the lib files for boost on the right path (and make sure they're installed/built too, which they might not be). I'm not sure how to get them on the right path with g++ because I haven't used MingGW, I've only used boost with Visual Studio.