it looks like PGI 16.7 does not support initializer lists introduced with the C++11 standard.
#include <vector>
#include <string>
#include <iostream>
int main(){
std::vector<std::string> string_vec = {"a string"};
for(const auto& s : string_vec){
std::cout << s << std::endl;
}
std::vector<double> double_vec = { 3.4 };
for(const auto& d : double_vec){
std::cout << d << std::endl;
}
return 0;
}
The above example compiles (and runs) fine using GCC 5.2 (g++ -std=c++11 initializer_list.cpp), however, using PGI 16.7 the compiler issues two errors:
$ pgc++ --version
pgc++ 16.7-0 64-bit target on x86-64 Linux -tp haswell
The Portland Group - PGI Compilers and Tools
Copyright (c) 2016, NVIDIA CORPORATION. All rights reserved.
$ pgc++ --c++11 initializer_list.cpp
"initializer_list.cpp", line 7: error: no instance of constructor
"std::vector<_Tp, _Alloc>::vector [with _Tp=std::string,
_Alloc=std::allocator<std::string>]" matches the argument list
argument types are: (const char [9])
std::vector<std::string> string_vec = {"a string"};
^
"initializer_list.cpp", line 12: error: copy-list-initialization cannot use a
constructor marked "explicit"
std::vector<double> double_vec = { 3.4 };
^
2 errors detected in the compilation of "initializer_list.cpp".
When I add more items to the initializer lists the error messages change and the compiler complains about code in “/usr/include/c++/4.4.7/bits/stl_iterator_base_types.h”, which makes me wonder why it is looking in header files that seem to correspond to GCC 4.4.7.
Is my environment screwed up or is this a compiler bug or a C++11 feature not yet fully supported?
On a side note, it also seems that pgc++ 16.7 does not handle statements such as “#pragma GCC …”.
E.g. for #pragma GCC system_header I get a compile error whereas for #pragma GCC diagnostic … I just get warnings.
The boost library contains such GCC pragma statements and I basically have to edit all boost header files containing such statements if I want my program to use boost. It is not a showstopper, but kind of inconvenient if the production environment is based on GCC and would not need any modifications of the boost library.
The problem is the missing C++11 support in g++ 4.4.7. You need to be
at least g++ 4.8.3 to have C++11 support. We need the correct g++ headers
and runtime libs to support this capability in pgc++.
I am working on a RHEL 6.6 system, which uses gcc 4.4.7 as system compiler, but I do have more recent gcc versions available on the filesystem. Actually, all the libraries my program is linked against haven been compiled with gcc 5.2.
Is there a way to point pgc++ to one of the more recent versions of gcc, I guess ideally to 5.2, available on my system. For system headers is it enough to specify -I<path to include dir of gcc 5.2 installation>? I probably need to do something similar for the linking stage so that the right libraries are selected, i.e. can I overwrite the defaults of pgc++?
We tried to reinstall PGI compiler with gcc 5.2 (before I read your response) in the PATH variable before any other gcc version, but when I run pgc++ -drystdinc I still get the following:
So it seems that this doesn’t do the trick. Actually, the install_env script seems to reset the PATH variable right at the beginning to /usr/bin/:/bin/:/sbin:$PATH. Does this mean I need to upgrade the OS version of RHEL so that pgc++ can grab a c++11 compliant system compiler or it just fell back to the system compiler because (as you mentioned) gcc 5.2 is not yet supported. Please advise what I need to do to install a c++11 compliant version of pgc++.
Let’s say I have managed to install pgc++ with g++ 4.8.3 or 4.9.2. Will I be able to link against libraries that have been built with gcc 5.2, 5.1, or 5.0?
OK, I got that part, but I still don’t know how to install PGI compiler with a gcc version other than the system gcc compiler version or whether that’s even possible. Or do I need to upgrade my RHEL version so that I have a more recent gcc version as system compiler.
both my IT support and myself (in my home directory) have followed your instructions, i.e. gcc 4.9.2 is in the PATH and gcc --version confirms it, but running pgc++ -drystdinc allows points to gcc 4.4.7 instead of 4.9.2, i.e the output looks like:
So something does not seem to be working. Have you tried to do this with 16.7 at your end? As I mentioned in an earlier post, looking at the install script the following is done at the very beginning:
So it seems whatever PATH I set, the installer will always find /usr/bin/gcc first, which is not the gcc I want. I could try to comment out the line where the PATH is changed, but I am wondering what side effects this could have if I start messing around with the install script.