Warum funktioniert __attribute __ ((Konstruktor)) in einer statischen Bibliothek nicht?

Im folgenden Beispiel sollte das Programm "foo called" ausgeben:

// foo.c
#include <stdio.h>

__attribute__((constructor)) void foo()
{
    printf("foo called\n");
}

// main.c
int main()
{
    return 0;
}

Wenn das Programm so kompiliert ist, funktioniert es:

gcc -o test main.c foo.c

Wenn jedoch foo.c in eine statische Bibliothek kompiliert wird, gibt das Programm nichts aus.

gcc -c main.c
gcc -c foo.c
as rcs foo.a foo.o
gcc -o test foo.a main.o

Warum passiert das?

Antworten auf die Frage(2)

Ihre Antwort auf die Frage