Gentoo Archives: gentoo-alt

From: Matt Michalowski <nextdayflight@×××××.com>
To: gentoo-alt@l.g.o
Subject: [gentoo-alt] gcc-apple and C++ exceptions
Date: Wed, 26 May 2010 23:23:42
Message-Id: AANLkTim6BCATtNCmVSHDGTOTQteCpyLrpR3CtZNB49Ks@mail.gmail.com
1 Hi all - first, a little test program, test.cpp:
2 ----
3 #include <iostream>
4 #include <stdexcept>
5
6 int main(int argc, char* argv[])
7 {
8 using namespace std;
9
10 try
11 {
12 throw runtime_error("runtime_error");
13 }
14 catch (const std::runtime_error& re)
15 {
16 cout << "Caught runtime_error: " << re.what() << endl;
17 }
18
19 return 0;
20 }
21 ----
22
23 When I compile this with my XCode g++ (gcc version 4.2.1 (Apple Inc.
24 build 5659)) , it works as expected:
25 $ /usr/bin/g++ -o test test.cpp
26 $ otool -L ./test
27 ./test:
28 /usr/lib/libstdc++.6.dylib (compatibility version 7.0.0,
29 current version 7.9.0)
30 /usr/lib/libSystem.B.dylib (compatibility version 1.0.0,
31 current version 125.0.1)
32 $ ./test
33 Caught runtime_error: runtime_error
34
35 However, with my gentoo-alt gcc-apple g++ (gcc version 4.2.1 (Gentoo
36 4.2.1_p5659, Apple Inc. build 5659):
37 $ g++ -o test test.cpp
38 $ otool -L ./test
39 ./test:
40 /Users/mattm/gentoo/usr/lib/gcc/x86_64-apple-darwin10/4.2.1/libstdc++.6.dylib
41 (compatibility version 7.0.0, current version 7.9.0)
42 /usr/lib/libSystem.B.dylib (compatibility version 1.0.0,
43 current version 125.0.1)
44 $ ./test
45 terminate called after throwing an instance of 'std::runtime_error'
46 Abort trap
47
48 I've tried a few flags (-fexceptions, etc.), but I still can't get any
49 C++ code compiled with the gentoo-alt gcc-apple to catch exceptions
50 properly. Any ideas?
51
52
53 Matt.

Replies

Subject Author
Re: [gentoo-alt] gcc-apple and C++ exceptions Fabian Groffen <grobian@g.o>