RE: Executable shared object

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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 libexpm.so exp1.o exp2.o exp3.o 

This would create a normal shared object file libexpm.so

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

#include<stdio.h>
#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("./libexmp.so", RTLD_LAZY);
func_to_call = dlsym(lib, "func_to_call");
(*func_to_call)("++ETM++");
dlclose(lib);
}

Now you can make an excutable .so out of this by:
gcc -fPIC -c libuseso.c
ld -dy -o libuseso.so 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,
Pradyuman.

-----Original Message-----
From: Paolo Massimino [mailto:paolo.massimino@xxxxxxxxxxxx]
Sent: Wednesday, July 02, 2003 8:51 PM
To: gcc-help@xxxxxxxxxxx
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
Paolo


[Index of Archives]     [Linux C Programming]     [Linux Kernel]     [eCos]     [Fedora Development]     [Fedora Announce]     [Autoconf]     [The DWARVES Debugging Tools]     [Yosemite Campsites]     [Yosemite News]     [Linux GCC]

  Powered by Linux