Autor Beitrag
Aya
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 1964
Erhaltene Danke: 15

MacOSX 10.6.7
Xcode / C++
BeitragVerfasst: Di 09.03.10 01:32 
Hi,

ich bin dabei mir eine *.lib zu erstellen für mein aktuelles Projekt.

Das ganze habe ich unter MacOSX entwickelt und dort ebenfalls eine lib (*.a) erstellt.

In einer der cpp-dateien der lib habe ich so etwas:

static MyClass myDefaultClass;

Wenn ich die lib in mein Projekt einbinde und das Projekt starte, wird unter MacOSX das static direkt als erstes initialisiert (sehe ich an einem printf im constructor von MyClass).

Unter Windows allerdings kommt nix.. also es scheint als würde das static in der Lib nicht initialisiert werden..

Hat jemand ne idee warum das ganze unter Windows/VC++ nicht initialisiert wird??
Muß ich da bei der Lib evtl irgendwelche speziellen compiler-flags einstellen?

Aya~

_________________
Aya
I aim for my endless dreams and I know they will come true!
Aya Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 1964
Erhaltene Danke: 15

MacOSX 10.6.7
Xcode / C++
BeitragVerfasst: Di 09.03.10 22:18 
Ich glaub ich hab es etwas schwierig erklärt, deswegen hier mal ein beispiel:

Header:
ausblenden Quelltext
1:
2:
3:
//n.h

int n();


CPP Datei:
ausblenden Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
//n.cpp

int n()
{
  static int sn = 0;
  return ++sn;
}

static int a = n();
static int b = n();
static int c = n();
static int d = n();


Jetzt erstell ich ein simples commandline tool:

ausblenden Quelltext
1:
2:
3:
4:
5:
6:
7:
#include <n.h>

int main()
{
  printf("%i", n());
  return 0;
}


So, ich habe jetzt also 2 cpp dateien und 1 header.
Wenn ich alles drei zusammen in einem Project compiliere und dann starte, bekomme ich als ausgabe wie erwartet "5".

Wenn ich jetzt n.cpp zu einer statischen-library compiliere und diese dann in meinem projekt einbinde (also die n.cpp aus dem projekt entferne und die erzeugte n.lib einbinde), und dann starte bekomme ich als ergebnis nur "1"... also a, b, c und d wurden nicht initialisiert...

Hat irgendwer eine idee?

Aya~

PS: Hab es jetzt als crosspost im DelphiGL-Forum -> www.delphigl.com/for...c.php?f=4&t=9075

_________________
Aya
I aim for my endless dreams and I know they will come true!