Review your favorite Linux distribution.
Go Back > Forums > Non-*NIX Forums > Programming
User Name
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.


  Search this Thread
Old 02-24-2006, 09:54 PM   #1
Registered: Mar 2005
Posts: 60

Rep: Reputation: 15
Call back method for shared library

Hi All,

i wrote an application which loads shared libraries at run time.
my question : is there any way a shared libray can call a method/funtion which is defines in the application?

Can we do this ?if yes how to do it.

Can any one help me?

thanks in adavnce
Old 02-25-2006, 01:10 AM   #2
LQ Guru
Registered: Mar 2004
Distribution: SusE 8.2
Posts: 5,863
Blog Entries: 1

Rep: Reputation: Disabled
Sure - just use a "callback":

1. Your library function has a parameter that's a pointer to a function.

2. You program that calls the library function defines the actual function
(which is the "callback function.

3. When your program calls the library function, it passes the callback.

4. Your library invokes the callback.

Examples of "callbacks" are numerous:

* signal handlers (in the Linux world)
* WinProc (in "classic Windows" programming)
* GTK+ event handlers
* etc etc

Try "man signal", for example.
Old 02-25-2006, 11:43 AM   #3
Senior Member
Registered: Aug 2002
Location: Groningen, The Netherlands
Distribution: Debian
Posts: 2,536

Rep: Reputation: 111Reputation: 111
The code of cpufreqd is a nice real-world example about how to load shared libraries as 'plugins' and let them register several call-back functions that get called from the main program.

As it is a complete program, it may look a bit tedious to dive into, but the code is quite clean IMHO, and not too big.


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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
Where can I get every shared library at? Balkman Linux - General 2 08-28-2004 10:56 PM
help shared library jingle_mj Programming 4 08-13-2004 04:13 AM
help shared library jingle_mj Linux - General 1 08-13-2004 03:11 AM
howto compile bin with my library using all-static and shared linked standart library stpg Programming 4 06-29-2004 04:20 AM
Call Back penguin Linux - Networking 0 01-20-2004 03:22 PM > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 05:04 PM.

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