I believe both of these are happening: hmahmood@...> g++ -fPIC -fexceptions -frtti -shared main.cpp -v Using built-in specs. Target: i586-suse-linux Configured with: ../configure --enable-threads=posix --prefix=/usr --with-local-prefix=/usr/local --infodir=/usr/share/info --mandir=/usr/share/man --libdir=/usr/lib --libexecdir=/usr/lib --enable-languages=c,c++,objc,fortran,obj-c++,java,ada --enable-checking=release --with-gxx-include-dir=/usr/include/c++/4.2.1 --enable-ssp --disable-libssp --disable-libgcj --with-slibdir=/lib --with-system-zlib --enable-shared --enable-_cxa_atexit --enable-libstdcxx-allocator=new --disable-libstdcxx-pch --program-suffix=-4.2 --enable-version-specific-runtime-libs --w ithout-system-libunwind --with-cpu=generic --host=i586-suse-linux Thread model: posix gcc version 4.2.1 (SUSE Linux) /usr/lib/gcc/i586-suse-linux/4.2.1/cc1plus -quiet -v -D_GNU_SOURCE main.cpp -quiet -dumpbase main.cpp -mtune=generic -auxbase main -version -fPIC -fexceptions -frtti -o /tmp/ccBVxqAa.s #include "..." search starts here: #include <...> search starts here: /usr/include/c++/4.2.1 /usr/include/c++/4.2.1/i586-suse-linux /usr/include/c++/4.2.1/backward /usr/local/include /usr/lib/gcc/i586-suse-linux/4.2.1/include /usr/lib/gcc/i586-suse-linux/4.2.1/../../../../i586-suse-linux/include /usr/include End of search list. GNU C++ version 4.2.1 (SUSE Linux) (i586-suse-linux) compiled by GNU C version 4.2.1 (SUSE Linux). GGC heuristics: --param ggc-min-expand=99 --param ggc-min-heapsize=129418 Compiler executable checksum: 87d7be6f5d9de7847748ea6085e60774 /usr/lib/gcc/i586-suse-linux/4.2.1/../../../../i586-suse-linux/bin/as -V -Qy -o /tmp/ccoQIilQ.o /tmp/ccBVxqAa.s GNU assembler version 2.17.50 (i586-suse-linux) using BFD version (GNU Binutils) 2.17.50.20070726-14 (SUSE Linux) /usr/lib/gcc/i586-suse-linux/4.2.1/collect2 --eh-frame-hdr -m elf_i386 -shared /usr/lib/gcc/i586-suse-linux/4.2.1/../../../crti.o /usr/lib/gcc/i586-suse-linux/4.2.1/crtbeginS.o -L/usr/lib/gcc/i586-suse-linux/4.2.1 -L/usr/lib/gcc/i586-suse-linux/4.2.1 -L/usr/lib/gcc/i586-suse-linux/4.2.1/../../../../i586-suse-linux/lib -L/usr/lib/gcc/i586-suse-linux/4.2.1/../../.. /tmp/ccoQIilQ.o -lstdc++ -lm -lgcc_s -lc -lgcc_s /usr/lib/gcc/i586-suse-linux/4.2.1/crtendS.o /usr/lib/gcc/i586-suse-linux/4.2.1/../../../crtn.o hmahmood@...> ldd a.out linux-gate.so.1 => (0xffffe000) libstdc++.so.6 => /usr/lib/libstdc++.so.6 (0xb7ef1000) libm.so.6 => /lib/libm.so.6 (0xb7ecc000) libgcc_s.so.1 => /lib/libgcc_s.so.1 (0xb7ec0000) libc.so.6 => /lib/libc.so.6 (0xb7d8d000) /lib/ld-linux.so.2 (0x80000000) On Wed, Apr 22, 2009 at 4:19 PM, Ian Lance Taylor <iant@xxxxxxxxxx> wrote: > Hasan Mahmood <hasan.mahm@xxxxxxxxx> writes: > >> I am having a problem trying to catch std::runtime_error (thrown from >> libstdc++) in a .so I built with -fPIC. If I build without -fPIC, I >> can catch the exception. Here is the code in the .so: > > What operating system are you using? > > What version of gcc are you using? > > What happens when the program does not work as you expect? > > In general you can only catch an exception thrown by a shared library if > you are using a shared libgcc or if you are using a linker which > supports the --eh-frame-hdr option. So first confirm that one or the > other is the case. Use ldd to see whether you are linking against a > shared libgcc (named libgccc_s). Use -v when linking to see whether gcc > pases --eh-frame-hdr to the linker. > > Ian >