C++ exceptions are broken in FreeBSD with gcc-compiled code?
Yuri
yuri at rawbw.com
Wed Apr 9 17:03:01 UTC 2008
I am unable to make a C++ program to catch an exception using the the
system g++ compiler.
> cat exc.C
#include <iostream>
#include <string>
using namespace std;
int main() {
try {
throw string("String");
} catch (string s) {
cout << "Caught an exception \"" << s << "\"\n";
}
}
* Failed attempts with system compiler (using /lib/libgcc_s.so.1 and
/usr/lib/libstdc++.so.6):
> echo $LD_LIBRARY_PATH
> g++ -fexceptions -o exc exc.C
> exc
Exception raised: Memory allocation failure!
> g++ -pthread -fexceptions -o exc exc.C
> exc
Exception raised: Memory allocation failure!
* Succeeded attempt with gcc-4.3.0 and -pthread option (using
/usr/local/gcc-4.3.0/lib/libgcc_s.so.1 and
/usr/local/gcc-4.3.0/lib/libstdc):
> echo $LD_LIBRARY_PATH
/usr/local/gcc-4.3.0/lib
> /usr/local/gcc-4.3.0/bin/g++ -pthread -fexceptions -o exc exc.C
> exc
Caught an exception "String"
* Failed attempt with gcc-4.3.0 without -pthread option (using
/usr/local/gcc-4.3.0/lib/libgcc_s.so.1 and
/usr/local/gcc-4.3.0/lib/libstdc):
> echo $LD_LIBRARY_PATH
/usr/local/gcc-4.3.0/lib
> /usr/local/gcc-4.3.0/bin/g++ -fexceptions -o exc exc.C
> exc
Abort trap: 6
So exceptions *only* work with new gcc-4.3.0 and -pthread option.
Is this a known issue?
> g++ --version
g++ (GCC) 4.2.1 20070719 [FreeBSD]
> uname -a
FreeBSD xxx.xxx.xxx 7.0-STABLE FreeBSD 7.0-STABLE #5: Thu Feb 28
03:58:20 PST 2008 yuri at xxx.xxx.xxx:/usr/obj/usr/src/sys/GENERIC i386
Yuri
More information about the freebsd-hackers
mailing list