Activating C++11 support in Clang - c++

I've downloaded and built clang version 3.0 in order to play around a bit with C++11 features, however I get this error (even though I am using the -Wc++11-extensions flag).
S:\llvm\code>clang++.exe -Wc++11-extensions variadic.cpp
variadic.cpp:4:19: warning: variadic templates are a C++11 extension [-Wc++11-extensions]
template <typename... Args>
I've built clang with VS10 on Windows 7 (64bit) and the build passed successfully.
Edit: As #cli_hlt pointed out this is a warning not an error, the error is something I did not paste unable to execute command: program not executable. The root cause for that was that link.exe was not in the PATH. Once I ran from a VS command prompt all was well.

You are getting a warning, not an error.
The -W switch is used to enable compiler warnings. So for my understanding, by using -Wc++11-extensions you tell the compiler to warn you if you are using C++11 extensions.
And thats exactly what happens here.

Related

Problem with using clang as compiler for code::blocks

I installed llvm for clang, because I wanted to use clang for code::blocks as compiler, since I need compiler that supports c++20, so I installed llvm, the bin was added in environmental variables, even the code::blocks detected llvm as compiler, however I get error when i want to compile my code:
-------------- Build file: "no target" in "no project" (compiler: unknown)---------------
clang++.exe -c C:\Users\Temirlan\labs\lab4\rpn.cpp -o C:\Users\Temirlan\labs\lab4\rpn.o
clang++.exe -o C:\Users\Temirlan\labs\lab4\rpn.exe C:\Users\Temirlan\labs\lab4\rpn.o
C:\Users\Temirlan\labs\lab4\rpn.cpp:180:10: fatal error: 'iostream' file not found
#include <iostream>
^~~~~~~~~~
1 error generated.
Do you know what is the problem or maybe the picture will help?
photo of compiler executables in code::blocks
I got error of "fatal error: 'iostream' file not found"
All modern compilers support C++20 (to slightly varying extent): both Clang, GCC, and MSVC. So this shouldn't affect your choice (but I do think that Clang is the best option).
Clang can be set up in different ways: (in order of personal preference)
With GCC's standard C++ library, libstdc++. Install MSYS2, then use it to install both Clang and GCC: pacman -S mingw-w64-ucrt-x86_64-gcc mingw-w64-ucrt-x86_64-clang. Then use C:/msys64/ucrt64/bin/clang++.exe as the compiler. (There's also MINGW64 variant instead of UCRT64, read about the difference here).
With its own standard C++ library, libc++. Install MSYS2, then use it to install libc++-flavored Clang: pacman -S mingw-w64-clang-x86_64-clang. Then use C:/msys64/clang64/bin/clang++.exe as the compiler.
With MSVC's standard C++ library, aka MSVC STL. Install the official Clang build, and install Visual Studio.
Note that the first two options don't involve downloading the official Clang build. The official build wants the MSVC STL by default, which you don't have, since you didn't install VS. (And if you do install it, you might as well use it instead of CodeBlocks.)
The official Clang build can be made to work with other standard libraries, but they need to be installed separately, and you need to persuade it with some compiler flags. It's easier to install the MSYS2's version, which already uses the correct flags by default.

"enable_if_t" not a type gcc 8.3.1

System specifications: Centos 7 with devtoolset-8 enabled (gcc 8.3.1), cmake 3.14.6
I seem to have an error regarding gcc versioning causing a 'type error'
I am trying to build a gitlab project (https://github.com/ColinKennedy/USD-Cookbook/tree/master/plugins/custom_resolver) which needs a built version of Pixar's USD. I've already successfully built USD and run the following commands to build the custom resolver project and provide it the location of USD:
scl enable devtoolset-8 bash
USD_INSTALL_ROOT=/home/fernandos/Documents/USD cmake ..
make install
however during make install this error pops up:
/home/fernandos/Documents/USD/include/pxr/base/tf/hash.h:44:6: error: ‘enable_if_t’ in namespace ‘std’ does not name a template type
std::enable_if_t<std::is_integral<T>::value>
This type error seems to indicate an error possibly caused by a wrong version of gcc if I look at other stack overflow posts. I know that enable_if_t was added in c++14, so if you have an old compiler (such as the standard gcc 4.8.1 on Centos 7) it would throw this error as it standard uses c++11 to compile.
However, I'm using the devtoolset-8 environment and everything seems to indicate that I am using gcc 8.3.1 to compile (I even make the MakeFile print the version out). So, how is it possible that I get this error, does gcc 8.3.1 not know this type?
I also noticed that the error originates from my USD build: I am not sure if this matters, but I built it with gcc 6.3.1 (which certainly knows the enable_if_t type). As I am relatively new to building on linux with cmake/make could this cause problems?

'function' does not name a type (in Eclipse)

I am using the library <functional> which defines the class function. But when I try to compile the code I get an error that function does not name a type.
Till recently I was using Microsoft Visual Studio and there was no problem. Now I sometimes work on Ubuntu 14.04 with Eclipse and g++ and got this error when compiling the same code (except the 'main').
I found here some similar problems but none of the solution works for me.
#include <functional>
using namespace std;
typedef function<double(double, double*)> t_function;
error on third line, I also tried different (and no namespaces) with different using and none works
You either have an old version of gcc (less likely), or not compiling in c++11 mode (more likely), which is enabled with a compiler flag:
C++11 features are available as part of "mainline" GCC in the trunk of GCC's repository and in GCC 4.3 and later. To enable C++0x support, add the command-line parameter -std=c++0x to your g++ command line. Or, to enable GNU extensions in addition to C++0x extensions, add -std=gnu++0x. GCC 4.7 and later support -std=c++11 and -std=gnu++11 as well.
This question describes the process of enabling c++11 in Eclipse in-detail, though it is rather old.

Clang : Failed to find C++11 headers

I am trying to build all the examples in the Crow library with clang 3.6 and I can see the CC/CXX has been found properly by using clang 3.6. It uses cmake which I am not quite familiar with.
However it failed to find C++11 headers.
Error is like:
'future' file not found
It seems that the libstdc++ is not specified properly, or some people reckon it needs to build the clang libstdc++ myself.
Anyone can shed some light on this will be much appreciated.
So based on the previous comment the issue is that you don't enable the C++ 11 mode in Clang.
As in referenced question, the issue is simply that you do not say to Clang (or in future for GCC) to look for C++ headers.
"Clang's command line is gcc-compatible so you have to enable C++11 support via the followinf command-line switch"
-std=c++11
If after this you all you have to do is to write your C++ 11 code. If you use Makefiles you should add to your CXX arguments the command line switch to Clang.

How to use std::thread of C++ 11 under Cygwin GCC 4.7.2

I've been trying to compile a multithread hello-world program under Cygwin using the newly introduced C++ 11 std::thread feature without success. I compiled and installed GCC 4.7.2 by myself, and the same code works without any problems under Linux with the same version of GCC. The first error I got was that the compiler did not recognize the -pthread flag. After researching on it for a while I noticed someone said on Cygwin this flag should be -lthread. I made the change and that error was gone, but another series of errors occur telling me thread is not member of std. I wonder if it's caused by the wrong configuration of the compiler during installation, or std::thread is simply not supported under Cygwin?
This looks like you did not compile the program with the appropriate standard library flag. If you want to compile for C++11 you should use:
g++ --std=c++0x -o ...
The --std flag sets the appropriate language compatibility level. If this does not help, please post the error messages you got as a source listing.