This is the mail archive of the gcc-help@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

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;
}


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]