Using the -pg option to g++ results in the -R option to the linker being omitted. This may result in libstdc++ not being found during dynamic linking. I have attached the output of "g++ -v" with and without the -pg option; note that when it is present the -R/usr/local/gnu/lib argument is omitted.