This is the mail archive of the
gcc-help@gcc.gnu.org
mailing list for the GCC project.
export symbols
- From: Alberich de megres <alberich2k5 at gmail dot com>
- To: gcc-help at gcc dot gnu dot org
- Date: Fri, 24 Apr 2009 00:43:00 +0200
- Subject: export symbols
Hi,
i got a question about exporting symbols:
two files:
main.c: defines main and f1() and load module on b.c file ( compiled )
b.c : defines f2() which uses f1() after been loaded.
to compile b.c file i use:
gcc -shared -fPIC b.c -o b.so
And to compile main.c:
gcc main.c -o main -ldl -rdynamic
Everything works fine, but -rdynamic affects to all symbols on main.c
but i just want to export some of symbol on main.c. Is it some way to
control which symbols i export?
here are source code for main.c
-------------------------------------------------------------------
#include <stdio.h>
#include <dlfcn.h>
int main(int argc, char **argv)
{
int *handler;
double (*cosine)(double);
handler=(int*)dlopen("dym.mo", RTLD_LAZY);
if (!handler) {
printf( "!!! %s\n", dlerror() );
return;
}
cosine = dlsym(handler, "cos");
printf("coseno 1 =>%f",cosine(1));
return 0;
dlclose(handler);
}
int f1()
{
return 42;
}
-----------------------------------------------------------
and for bc.:
#include <stdio.h>
//#include <dlfcn.h>
double cos(double d)
{
printf("f1 returns->%e\n",f1());
return d;
}