global objects not initializing -- GCC 3.2.3

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

 



I'm looking for the reason why global objects defined in
statically-linked libraries are not initialized at run time. Example:

-------------------------------------------------------------------------------

bash@puma$ cat lib.cpp
#include <iostream>

class X
{
public:
  X()
  {
    std::cout << "Inside X constructor\n";
  }
};

// instantiate global object
X x;

bash@puma$ cat make_static 
g++ -g -c -o lib.o lib.cpp
ar -r libTest.a lib.o
stecklen(bash)@puma[link_test]$ ./make_static 
stecklen(bash)@puma[link_test]$ cat main.cpp
#include <iostream>

int main()
{
  std::cout << "Inside main.\n";

  return 0;
}
bash@puma$ cat make_bin 
g++ -g -I. main.cpp -L. -lTest -o main.out
bash@puma$ ./make_bin 
bash@puma$ ./main.out 
Inside main.
bash@puma$ 

-------------------------------------------------------------------------------

If I change the line that makes the lib to "g++ -shared -o libTest.so
lib.o" and recompile main, the object is initialized.

Why is this?


Thanks for any information.

[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