PGI C++11 support

Hi, I’m experiencing some problems compiling codes with C++11 features with pgc++ 17.4

Could someone tell me if this is supported:


#include <iostream>
#include <string>

int main()
{
   double f = 23.43;

   std::string f_str = std::to_string(f);
   std::cout << "f_str: " << f_str << "\n";

   return 0;
}

Error:

pgc++ --c++11 main.cpp -o test
"main.cpp", line 8: error: namespace "std" has no member "to_string"
     std::string f_str = std::to_string(f);
                              ^

1 error detected in the compilation of "main.cpp".

And std::to_string is defined in header so…
http://en.cppreference.com/w/cpp/string/basic_string/to_string

Is this a bug, or a functionality not yet supported by pgc++ ?

Make sure the g++ version also supports c++11/c++14, or pgc++
will fail as well.

g++ needs to be 4.8 or newer to support c++11
g++ needs to be 5.2 or newer to support c++11

Example. Your test.cpp

hsw1% g++ --version
g++ (GCC) 4.8.5 20150623 (Red Hat 4.8.5-4)

hsw1% pgc++ -o test test.cpp
“test.cpp”, line 8: error: namespace “std” has no member “to_string”
std::string f_str = std::to_string(f);
^

1 error detected in the compilation of “test.cpp”.

hsw1% pgc++ -o test test.cpp -std=c++11
compiles no problem.

===============================================
nehalem01% g++ --version
g++ (GCC) 4.1.2 20080704 (Red Hat 4.1.2-44)

nehalem01% pgc++ -o test test.cpp
“test.cpp”, line 8: error: namespace “std” has no member “to_string”
std::string f_str = std::to_string(f);
^

1 error detected in the compilation of “test.cpp”.
nehalem01% pgc++ -o test test.cpp -std=c++11
“test.cpp”, line 8: error: namespace “std” has no member “to_string”
std::string f_str = std::to_string(f);
^

1 error detected in the compilation of “test.cpp”.

So it fails when g++ does not also support the newer standards.

dave

Thanks for your reply!

Unfortunately I’m working in a machine with ‘modules’ and moving from g++ < 4.9 to g++ > 5.2 doesn’t seem to work:

$ module purge
$ module load gcc/4.9.4
load gcc/4.9.4 (PATH, MANPATH, LD_LIBRARY_PATH)
$ g++ --version
g++ (GCC) 4.9.4

$ g++ -std=c++11 test.cpp -o test
$ $ ./test 
f_str: 23.430000
$ module load pgi/17.4
load pgi/17.4 (PATH, MANPATH, LD_LIBRARY_PATH, LM_LICENSE_FILE)
$ pgc++ --c++11 test.cpp -o test
"test.cpp", line 8: error: namespace "std" has no member "to_string"
     std::string f_str = std::to_string(f);
                              ^

1 error detected in the compilation of "test.cpp".

Same happens if I load a newer g++ version like 6 or 7.

I suspect that pgc++ is ignoring the current loaded g++ version and is using the default one from the system. Is this possible? When does pgc++ detect the g++ version? At run time or at installation time?

Default g++ version in that system:

$ module purge
$ g++ --version
g++ (GCC) 4.4.7 20120313 (Red Hat 4.4.7-16)

Thanks

Finally, with help from my system manager I was able to solve this issue using makelocalrc.

makelocalrc /apps/PGI/pgi-17.4/linux86-64/17.4 -gcc /apps/GCC/6.3.0/bin/gcc -gpp /apps/GCC/6.3.0/bin/g++ -g77 /apps/GCC/6.3.0/bin/gfortran -x -d $HOME
mv $HOME/localrc $HOME/.mypgcpprc

PD: I also found the undocumented flag

--gnu_version <version>

but it worked for some files and not others.

Pau

makelocalrc does not handle the non-default gcc/g++ versions
well. Those switches are more for what g++ and gcc and gfortran
are named, and not a path to the different versions.

If you look at
pgc++ -v test.cpp -std=c++11
and
g++ -v test.cpp -std=c++11
you will probably see that pgc++ uses different assemblers and other
components than the version of g++ is using.

If you have ‘locate’ on your linux system, you can do the following

  1. If you have not installed 17.4 as a ‘Network Install’, remove it and
    reinstall selecting a Network type.

  2. cd $PGI/linux86-64/17.4/bin
    chmod +x ./addlocalrc

  3. And then run ‘addlocalrc’
    and it will create a localrc.something for each gcc version it finds.

  4. Each time you wish to use a version of gcc, find its localrc.xxx
    file and

setenv PGI_LOCALRC /full/path/to/localrc.xxx

and the compilers should now use the newer gcc.

The network install allows for multiple gcc versions, and
addlocalrc creates any localrc files you will need. The two together
means a single install can handle multiple gcc versions.
This process is meant for multiple platform/linux types to share
a common PGI installation.

regards,
dave

Does addlocalrc have flags to specify other gcc’s?

$ 
./addlocalrc 
Usage: addlocalrc [release_dir]
  The release_dir is defaulting to /home/myhome
 
Do you want to continue? (y/n) y
 
Only one working gcc executable was found on this system
It was found in the default location,  /usr/bin/gcc
 
Do you want to continue? (y/n) y
 
This script has located one or more gcc executables. 
For each gcc executable found, you have the option to configure 
the PGI compilers for use with those header files and libraries by 
generating a GNU-version-specific localrc file.
 
The localrc file used by pgcc and pgc++ can be controlled by using 
the PGI_LOCALRC environment variable at compilation time. 
 
This script can be rerun at any time, for instance, after a new 
version of the GNU toolchain has been installed. 
 
For each GNU executable found, choose whether to proceed with the 
configuration, skip that version, or quit this script. 
 
 
Configuring PGI for gcc found at /usr/bin/gcc (default), GNU version 4.4.7
 
Proceed, Skip, or Quit? (p/s/q)
$ gcc --version
gcc (GCC) 4.9.4
Copyright (C) 2015 Free Software Foundation, Inc.
...
$ which gcc
/apps/GCC/4.9.4/bin/gcc

addlocalrc can’t see the gcc version I want. It’s still picking the gcc from the system.

Send the output dialogs of

g++ -v xx.cpp

and

pgc++ -v xx.cpp

and

pgc++ -dryrun xx.cpp

where x.cpp is a simple hello program, to trs@pgroup,com
and we will see if we can manually create the localrc you need.


dave