Solved

Developing plugins: shmop vs dlopen

Posted on 1997-11-12
2
296 Views
Last Modified: 2013-12-26
I am trying to implement the concept of plugins for an application that we are writing.  I am thinking about using shared arenas to communicate between the main application and the plugins.  I'm new at this, and I'm not sure if this is the best way to go.  I have heard about dlopen, but I don't have alot of documentation on how to use it.

Which would be better to use, shmop or dlopen/dlsym?  Also, can anyone lead me to good resource on dlopen?

By the way, the application and plugins will be in C, and we are running IRIX 6.2.  And, platform portability is an issue; we want to be able to port to Windows NT.

Thanks,
Ash
0
Comment
Question by:chopin111297
2 Comments
 
LVL 4

Accepted Solution

by:
jos010697 earned 100 total points
ID: 1295584
You can definitely use dlopen and friends. Compile and link
your plugin as a shared object (a dynamic link library). Check
your manuals for the appropriate linker flags. Suppose the
name of this shared object is 'foo.so' and it contains a
functions 'bar'. This is the way to run this function from
your main application:

typedef int (*fp_t)(int); /* a function poiner */

void* so_object;
fp_t  func;

if (so_object= dlopen("foo.so", 1)) { /* open shared object */
   if (func= dlsym(so_object, "bar") {  /* get address of bar */
      printf("bar42 returned %d\n", func(42));
   else
      printf("couldn't find bar: %s ...\n", dlerror());

   dlclose(so_object); /* close shared object */
}
else
   printf("couldn't open foo.so: %s\n", dlerror());

That's basically all there is to it:

1: dlopen() the shared object
2: retrieve the address of a function (or data) using dlsym()
3: close everthing afterwards using dlclose()
4: if an error occured, dlerrror() returns an error string

kind regards,

Jos aka jos@and.nl

0
 

Author Comment

by:chopin111297
ID: 1295585
Does anyone know of a good resource on the use of dlopen?
0

Featured Post

Complete VMware vSphere® ESX(i) & Hyper-V Backup

Capture your entire system, including the host, with patented disk imaging integrated with VMware VADP / Microsoft VSS and RCT. RTOs is as low as 15 seconds with Acronis Active Restore™. You can enjoy unlimited P2V/V2V migrations from any source (even from a different hypervisor)

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Change owner from userA to server Local Administrators 7 62
Prevent this page from creating additional dialogs. 3 531
if loop in java 3 142
sumHeights2  challenge 7 103
Introduction: The undo support, implementing a stack. Continuing from the eigth article about sudoku.   We need a mechanism to keep track of the digits entered so as to implement an undo mechanism.  This should be a ‘Last In First Out’ collec…
In this article you will learn how to create a free basic website on Bitbucket, a git service provider. Polymer creates dynamic HTML components, which allow more flexibility than static HTML. This tutorial uses Ubuntu Linux but can also be done on W…
The purpose of this video is to demonstrate how to set up the WordPress backend so that each page automatically generates a Mailchimp signup form in the sidebar. This will be demonstrated using a Windows 8 PC. Tools Used are Photoshop, Awesome…
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.

773 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question