Solved

Developing plugins: shmop vs dlopen

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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Introduction: Load and Save to file, Document-View interaction inside the SDI. Continuing from the second article about sudoku.   Open the project in visual studio. From the class view select CSudokuDoc and double click to open the header …
Introduction: Finishing the grid – keyboard support for arrow keys to manoeuvre, entering the numbers.  The PreTranslateMessage function is to be used to intercept and respond to keyboard events. Continuing from the fourth article about sudoku. …
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.

758 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

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now