This is the mail archive of the
gcc@gcc.gnu.org
mailing list for the GCC project.
Re: Dynamic libraries
- To: cassino at tecgraf dot puc-rio dot br (Carlos Cassino)
- Subject: Re: Dynamic libraries
- From: hjl at lucon dot org (H.J. Lu)
- Date: Wed, 12 Aug 1998 13:57:38 -0700 (PDT)
- Cc: egcs at cygnus dot com
>
>
> Hello All.
>
> I'm using RedHat5.0, glibc & binutils updated and EGCS-1.0.3.
> I wrote a tiny C++ program that simply loads a (C++) dynamic library,
> calls a function and unloads it. The problem is that if an exception
> is thrown inside the library (and caught there) the program aborts.
> The output is:
>
> [alfa:~/tmp] app
> Abort
>
> In particular, if I comment out the "throw" line in the lib, everything
> works well. Does somebody knows what's going on? Since I have no idea
> about it, maybe I'm sending this to the wrong list--excuse me for that.
>
I have no problems with egcs 1.0.3 on RedHat 5.1. I don't
think Redhat 5.0 should be different.
> Please, c.c. the answer to me because I'm not a list member.
>
> Code for both files follows, app.cpp is the application and lib.cpp is
> the dynamic library.
>
> Thank you very much,
> -- Cassino
>
> --- app.cpp --------------------------------------
>
> #include <stdio.h>
> #include <dlfcn.h>
>
> int main(int argc, char **argv)
> {
> void* lib = dlopen("./liblib.so", RTLD_NOW);
> if (!lib)
> {
> printf("DLFCN error: %s\n", dlerror());
> return 1;
> }
> void* f = dlsym(lib, "f");
> if (!f)
> {
> printf("DLFCN error: %s\n", dlerror());
> return 2;
> }
> ((void(*)(void))f)();
> dlclose(lib);
> return 0;
> }
>
> --- lib.cpp --------------------------------------
>
> class Except
> {
> public:
> int code;
> Except(int c) : code(c) { }
> };
>
> static void g()
> {
> throw Except(1);
> }
>
> void cpp_f()
> {
> try {
> g();
> } catch (Except& ex) {
> }
> }
>
> extern "C" {
> void f(void)
> {
> cpp_f();
> }
> }
>
>
--
H.J. Lu (hjl@gnu.org)