Solved

Developing plugins: shmop vs dlopen

Posted on 1997-11-12
2
307 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

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Youtube.com 3 130
Detect CR LF to each line 12 170
lucky13 challenge 11 154
NotAlone Challenge 20 84
Introduction: Displaying information on the statusbar.   Continuing from the third article about sudoku.   Open the project in visual studio. Status bar – let’s display the timestamp there.  We need to get the timestamp from the document s…
Introduction: Ownerdraw of the grid button.  A singleton class implentation and usage. Continuing from the fifth article about sudoku.   Open the project in visual studio. Go to the class view – CGridButton should be visible as a class.  R…
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.

837 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