Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 1112579
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T02:44:02+00:00 2026-05-17T02:44:02+00:00

plugin1.cpp: #include <iostream> static class TestStatic { public: TestStatic() { std::cout << TestStatic create

  • 0

plugin1.cpp:

#include <iostream>

static class TestStatic {
public:
  TestStatic() {
     std::cout << "TestStatic create" << std::endl;
  }
  ~TestStatic() {
     std::cout << "TestStatic destroy" << std::endl;
  }
} test_static;

host.cpp

#include <dlfcn.h>
#include <iostream>
int main(int argc,char *argv[]) {
   void* handle = dlopen("./plugin1.so",RTLD_NOW | RTLD_LOCAL );
   dlclose(handle);
   return 0;
}

build and run:

>g++ -c plugin1.cpp -o plugin1.o -fPIC
>g++ -shared plugin.o -o plugin1.so
>g++ host.cpp -o host -ldl
>./host
>TestStatic create
>Segmentation fault

why TestStatic::~TestStatic called at ‘exit()’ but not at ‘dlclose()’ ?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-17T02:44:03+00:00Added an answer on May 17, 2026 at 2:44 am

    The C++ Standard requires that destructors be called for global objects when a program exits in the opposite order of construction. Most implementations have handled this by calling the C library atexit routine to register the destructors. This is problematic because the 1999 C Standard only requires that the implementation support 32 registered functions, although most implementations support many more. More important, it does not deal at all with the ability in most implementations to remove DSOs from a running program image by calling dlclose prior to program termination.

    This problem is addressed in later versions of GCC including C/C++ standard library and linker. Basically, C++ destructors should be registered using __cxa_atexit function instead of atexit (3).

    For the full technical details on __cxa_atexit, see Itanium C++ ABI specification.


    It is not clear from your question what version of the gcc, linker and standard C library you are using. Plus, the code you have provided does not meet POSIX standard as there are no RTDL_NOW or RTDL_LOCAL macros defined. They are RTLD_NOW and RTLD_LOCAL (see dlopen).

    If your C standard library does not support __cxa_atexit, you may need to disable it by specifying -fno-use-cxa-atexit gcc flag:

    -fuse-cxa-atexit

    Register destructors for objects with static storage
    duration with the __cxa_ atexit
    function rather than the atexit
    function. This option is required for
    fully standards-compliant handling of
    static destructors, but will only work
    if your C library supports
    __cxa_atexit.

    But that might result in a problem where destructors are called in different order or not called at all. So the best solution in case of broken __cxa_atexit support or no support at all is not to use static objects with destructors in your shared libraries.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 545k
  • Answers 545k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer I would advise against using the backspace key, since that… May 17, 2026 at 9:02 am
  • Editorial Team
    Editorial Team added an answer (Note: I'll assume that by "decode and dispatch" you mean… May 17, 2026 at 9:02 am
  • Editorial Team
    Editorial Team added an answer Non static properties (alias fields, alias member variables) have their… May 17, 2026 at 9:01 am

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Related Questions

// InternalTemplate.cpp : Defines the entry point for the console application. // #include stdafx.h
How do I properly include libraries in C++? I'm used to doing the standard
I get the below error when compiling my file. //Error PluginDiskstats.cpp:107: error: expected constructor,
My application accesses an Oracle database through Qt's QSqlDatabase class. I'm compiling Qt as
Greetings all, I have a code snippet as follows : class AppCtx { private:
Some Eclipse plugins are mandated by your environment. The appropriate source code management plugin,
I had a plugin installed in Visual Studio 2008, and it created some extra
There are several plugin options for building a search engine into your Ruby on
I'm using Subversive plugin in Ganymede, but after today's update it stopped working -
We've written a plugin to the Xinha text editor to handle footnotes. You can

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.