Re: c++ static object not created

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



> Can you give us an example of this not working?  It really should work,
> and it works for me.
Your example is really works.
I checked the difference in my case, and found that the problematic object is 
put in an archive file:

---------- x.cpp: -----------
#include <iostream>
using namespace std;
class SomeClass
{
public:
  SomeClass()
  {
    cout << "Hello!\n";
  }
};
static SomeClass my_instance;
------------- main.cpp: ------------
int main()
{
}
-----------------------------------------
What i did:
g++ main.cpp -c -o main.o
g++ x.cpp -c -o x.o
ar r x.a x.o
g++ -o good main.o x.o
g++ -o bad main.o x.a

Try to start 'bad' and 'good' executables: the 'bad' does not execute the 
constructor. Is there any difference in linking or I created the archive 
wrong way?

Regards
K. Gy.

[Index of Archives]     [Linux C Programming]     [Linux Kernel]     [eCos]     [Fedora Development]     [Fedora Announce]     [Autoconf]     [The DWARVES Debugging Tools]     [Yosemite Campsites]     [Yosemite News]     [Linux GCC]

  Powered by Linux