#pragma init and #pragma fini using gcc compiler on linux
Posted
by Josh
on Stack Overflow
See other posts from Stack Overflow
or by Josh
Published on 2010-03-17T04:10:49Z
Indexed on
2010/03/17
4:11 UTC
Read the original article
Hit count: 400
I would like to build some code which calls some code on loadup of the shared library. I thought i would do it like this:
#pragma init(my_init)
static void my_init () {
//do-something } int add (int a,int b) {
return a+b; }
So when i build that code with
gcc -fPIC -g -c -Wall tt.c
It returns
gcc -fPIC -g -c -Wall tt.c
tt.c:2: warning: ignoring #pragma init
tt.c:4: warning: ‘my_init’ defined but not used
So its warning my #pragmas. I tried this in real code and my code aborted because a function hadn't been called in the pragma section because it was ignored.
How do i get gcc to use these #pragma init and fini statemets?
© Stack Overflow or respective owner