This is the mail archive of the 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]

RE: Executable shared object

Hi Paolo,

Shared objects can be both executable and non-excutable type. This would depend on the way one has created the .so
In your case you can probably make a shared object library of all the object files that you have. Then write a wrapper object (which will be excutable type) which would use the shared library to call specific functions like ver etc.)

To do this :
1) Create normal shared boject library using gcc and ld of all the object files you want to have in the .so
eg., gcc -fPIC -c exp1.c exp2.c exp3.c
ld -G -o exp1.o exp2.o exp3.o 

This would create a normal shared object file

2) To write the wrapper:
create a wrapper libuseso.c which uses the previous functions 
by using dlopen() and dlsym() 
For example  a sample would be :

#include <dlfcn.h>      
int main()
void* lib;       
void (*func_to_call)(const char* str); 	/* lets say you want to call void func_to_call(char*) from earlier .so */

lib = dlopen("./", RTLD_LAZY);
func_to_call = dlsym(lib, "func_to_call");

Now you can make an excutable .so out of this by:
gcc -fPIC -c libuseso.c
ld -dy -o libuseso.o -ldl -lc

This would be an executable shared obj which can run from command line (might have to set LD_LIBRARY_PATH first)
This function could be a default func like version info etc.

Hope this helps,

Thanks & regards,

-----Original Message-----
From: Paolo Massimino []
Sent: Wednesday, July 02, 2003 8:51 PM
Subject: Executable shared object

Hi All!
I have a problem. I need to build a sherd object that, like libc do, can 
print some information when you execute it like a normal executable.
Anyone can help me ?
Thank you

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