Results 1 to 10 of 14
Hello,
let's say I have a master application which loads other plugins (.so dynamic libraries). When the plugin is loaded (dlopen) and its function "Load" is called by the master ...
- 10-14-2008 #1Just Joined!
- Join Date
- Jun 2008
- Posts
- 13
How should a plugin call its parent's function
Hello,
let's say I have a master application which loads other plugins (.so dynamic libraries). When the plugin is loaded (dlopen) and its function "Load" is called by the master application, the plugin should register its services in the master application.
So let there be a vector of services and a function "RegisterService" in the master application (files Services.h and Services.cpp). Function "RegisterService" registers a new service and updates the vector of services. How should a plugin call this "RegisterService" function and how should I compile it?
The problem is that if I don't compile plugin.cpp with Services.cpp, then during loading of the plugin there is an unresolved link to RegisterService call. If I compile it with Services.cpp, then these two functions (RegisterService) are two different functions and I cannot update the vector in master application.
Hope it's at least a little bit understandable.
Thanks for answers.
- 10-14-2008 #2
Could you post your code and make file...Thanks
- 10-14-2008 #3Just Joined!
- Join Date
- Jun 2008
- Posts
- 13
It's a little bit more of code so I put it as an attachment. In this configuration in runs but the plugin's service is not registered.
- 10-14-2008 #4Why are you compiling Services.cpp into g++ -o main main.cpp Services.cpp -ldl and then compiling Services.cpp as a shared object g++ -shared -o plugin.so Services.o plugin.o?#!/bin/sh
# first compile plugin
g++ -fPIC -g -c -Wall Services.cpp plugin.cpp && g++ -shared -o plugin.so Services.o plugin.o
# then compile master app
g++ -o main main.cpp Services.cpp -ldl
Ooops you explain that in the initial post
- 10-14-2008 #5
I tried compiling your program and had an error in int main (int argc, char ** argv[])
so I changed it to int main (int argc, char ** argv) and it compiled and ran...by ran I mean the program ran to completion without crashing
- 10-14-2008 #6Just Joined!
- Join Date
- Jun 2008
- Posts
- 13
- 10-14-2008 #7
This is the code in plugin.cpp
You make a call to RegisterService here...thats why you have to include Services.cpp while compiling the shared object or you get an "unresolved link to RegisterService call"Code:#include "plugin.h" void Load (void) { printf("Loading plugin...\n"); RegisterService("LS_PLUGIN",NULL); }
Basically the shared object can't resolve an address for RegisterService without compiling Services.cpp into it....
- 10-14-2008 #8Just Joined!
- Join Date
- Jun 2008
- Posts
- 13
So it means that dynamically linked library cannot use a function provided by its "parent"? The unresolved links in the library cannot be "bound" to the provided function?
- 10-14-2008 #9
You might and I stress might be able to pass the shared object a pointer to the the function in the host program...Hope this helps
- 10-14-2008 #10
I wrote a very small and simple shared object that receives a function pointer from the host program an it did work, it called and executed the host programs function without incident. The thing to stress is very small and simple shared object I'm not sure how this solution would work with a complicated function ...Hope this helps
the function I tried was:
Like I said a simple function...and all in all its a very complicated solution even for a simple functionCode:void printthis() { fprintf(stdout, "hello world!\n"); }


Reply With Quote
