This is the mail archive of the
gcc-help@gcc.gnu.org
mailing list for the GCC project.
RE: Executable shared object
- From: Singh Pradyuman-R50282 <Pradyuman dot Singh at motorola dot com>
- To: "'Paolo Massimino'" <paolo dot massimino at loquendo dot com>, gcc-help at gcc dot gnu dot org
- Date: Wed, 16 Jul 2003 12:18:15 +0530
- Subject: 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 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@loquendo.com]
Sent: Wednesday, July 02, 2003 8:51 PM
To: gcc-help@gcc.gnu.org
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