LinuxQuestions.org
Help answer threads with 0 replies.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 04-19-2007, 07:29 AM   #1
Bad_Lemon
LQ Newbie
 
Registered: Apr 2007
Posts: 1

Rep: Reputation: 0
Problem with dlopen in a plugin system ( C )


Hello all,

i'm trying to create a plugin system with the C language.
I am able to load the libs and get the functions I need, then I put them in a function pointer array to use them later.

There is a main source file and an additional one which is dedicated to plugins:

Code:
/**main.c**/

void (*init_proto_chain[20])(void *);

void init_protos(){
  
   (init_proto_chain[i])(data);

}
Code:
         /**plugins.c**/
extern (*init_proto_chain[20])(void*);

void load_plugins(){

  handle = dlsym("...libhttp.so",RTLD_NOW);

  void *func = dlsym(handle, "test");

  init_proto_chain[j] = ((void (*) (void *))func;

}
When I try to use any of the functions in the main code, I get a segfault and when I use gdb I can see there is nothing at the function address.

Yet, if I call "test()" by dereferencing func or init_proto_chain[j] when in load_plugins, it's working and the function pointer is valid.



Thanks in advance for any help.
 
Old 04-19-2007, 12:04 PM   #2
ta0kira
Senior Member
 
Registered: Sep 2004
Distribution: FreeBSD 9.1, Kubuntu 12.10
Posts: 3,078

Rep: Reputation: Disabled
The first call you make to 'dlsym' needs to be 'dlopen'. This opens the library whereas 'dlsym' extracts the symbol. Additionally, you always need to check the results of 'dlsym' and 'dlopen' for NULL and optionally output the result of 'dlerror' if either are NULL. The check to the handle should be made before calling 'dlsym' on it.
ta0kira
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Programming a plugin system... juanbobo Programming 9 07-19-2007 07:27 PM
LD_LIBRARY_PATH and dlopen smrcis Programming 5 03-08-2006 06:10 PM
plugin system and testing yogeshm02 Programming 2 03-05-2006 01:12 AM
problem with opening shared library using dlopen() in Red Hat Linux phani@tcs Linux - General 1 01-10-2006 03:49 PM
System lock-ups after installing flash plugin JaseP Linux - Software 1 03-15-2003 02:37 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 07:09 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration