Results 1 to 3 of 3

Thread: exception in shared libraries

  1. #1
    Join Date
    Nov 2006
    Posts
    19
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default exception in shared libraries

    Hi all,

    does somebody has experience handling exceptions within shared libraries on linux?

    I can dynamically load my shared library, but if I call a member function in my library which throws exceptions and try to catch it in my main program, I'll get following error:
    Program received signal SIGABRT, Aborted.
    Terminate called after throwing a instance of 'DBException'.

    (In debug mode).

    Loading the library in my main app:
    Qt Code:
    1. typedef DBFactory *create_t();
    2. create_t *create_object = (create_t*)QLibrary::resolve( "./libmylib.so", "create" );
    3.  
    4. if( create_object )
    5. {
    6. qDebug() << "Library loaded!!!" << '\n';
    7. dbFac = create_object();
    8. try
    9. {
    10. dbFac->checkConnection(); // in this function the exception will be thrown
    11. // but unfortunately the program crashs
    12. }
    13. catch( DBException &dbEx)
    14. {
    15. ...
    16. }
    17. }
    To copy to clipboard, switch view to plain text mode 

    Any help would be appreciated.
    Best regards
    big4mil
    Last edited by big4mil; 5th December 2006 at 00:30.

  2. #2
    Join Date
    Jan 2006
    Location
    Mountain View, CA
    Posts
    279
    Thanked 42 Times in 37 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: exception in shared libraries

    Exceptions cannot always safely be thrown across shared library boundaries.
    Have you tried linking with you library rather than dynamically loading it?
    Save yourself some pain. Learn C++ before learning Qt.

  3. #3
    Join Date
    Nov 2006
    Posts
    19
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: exception in shared libraries

    Thanks for your response.

    Yes that would be a way to solve my problem, but I prefer to load it dynamically.
    I've seen that there is a way to handle exception across shared libraries. The flag RTLD_GLOBAL must be set while loading the library:
    Qt Code:
    1. void* handle = dlopen( "./libdbconn.so", RTLD_NOW | RTLD_GLOBAL );
    To copy to clipboard, switch view to plain text mode 

    The library should then also be build with the following option:
    -Xlinker -export-dynamic
    Let me try that...
    cu
    big4mil

Similar Threads

  1. shared library problem
    By nhatkhang in forum KDE Forum
    Replies: 9
    Last Post: 28th November 2006, 05:07
  2. Shared lib template broken under linux ???
    By fullmetalcoder in forum Qt Programming
    Replies: 9
    Last Post: 26th April 2006, 21:05
  3. I got two problems when I used static compiled library of QT4
    By qintm in forum Installation and Deployment
    Replies: 8
    Last Post: 20th April 2006, 09:52
  4. Replies: 4
    Last Post: 7th March 2006, 09:52
  5. Exceptions and qApp->processEvents()
    By mcostalba in forum Qt Programming
    Replies: 3
    Last Post: 8th January 2006, 18:06

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.