Attribute constructor and static libraries?

Paco Moya Francisco.Moya@uclm.es
Fri Apr 11 12:05:00 GMT 2003


A simple example illustrates the problem:

p.c------------------------------------

void f(void) __attribute__((constructor));

void f(void)
{
	printf("Hola\n");
}

main.c----------------------------------

int
main()
{
	exit(0);
}
---------------------------------------

Now try compiling the example:

gcc -c p.c
gcc -c main.c
gcc -o first main.o p.o

And also in this way:

gcc -c p.c
gcc -c main.c
ar rcs libp.a p.o
gcc -o second main.o libp.a

The second version does not work as expected!

Any clue?

Thanks,

	Paco



More information about the Gcc-help mailing list