Link to home
Start Free TrialLog in
Avatar of KrzysztofRosinski
KrzysztofRosinskiFlag for Poland

asked on

Linux proxy library (between two libraries)

Hello,

I need to create library which will be like proxy between two other libraries. Exactly I have one high level library which use low level library. I would like to create small lib that implements all functions from low-level lib; do some job and call real method from low-level library. And I don't known how to comile something like this, without problems with repeat function names.

Example:
void function(void) {
  do_something();
  function(); // low level library
}

I figured that I could wrap low level functions e.g.
void wrap_function(void) {
  function();
}

And then use it in proxy library:
void function(void) {
  wrap_function();
}

But when I'm trying to run this I'm getting Segmentation fault because functions are looping:
(gdb) bt
#0  nfc_version () at main.c:5
#1  0x00000000004011fb in wrap_nfc_version ()
#2  0x0000000000400ddd in nfc_version () at main.c:5
#3  0x00000000004011fb in wrap_nfc_version ()
#4  0x0000000000400ddd in nfc_version () at main.c:5
#5  0x00000000004011fb in wrap_nfc_version ()
#6  0x0000000000400ddd in nfc_version () at main.c:5
#7  0x00000000004011fb in wrap_nfc_version ()
#8  0x0000000000400ddd in nfc_version () at main.c:5
#9  0x00000000004011fb in wrap_nfc_version ()
#10 0x0000000000400ddd in nfc_version () at main.c:5
#11 0x00000000004011fb in wrap_nfc_version ()
#12 0x0000000000400ddd in nfc_version () at main.c:5
#13 0x00000000004011fb in wrap_nfc_version ()
#14 0x0000000000400ddd in nfc_version () at main.c:5
(...)

Do you have any ideas how to solve this problem ?
Avatar of Infinity08
Infinity08
Flag of Belgium image

>> I would like to create small lib that implements all functions from low-level lib; do some job and call real method from low-level library.

That's called a wrapper. Your wrapper library will have to use different function names than the ones from the existing library.

Your code will then make calls to the functions implemented in the wrapper library.
/* your library function (declared in library.h) : */

void fun();


/* your wrapper library function : */

#include "library.h"

void wrap_fun() {
  /* do something before ... */
  fun();
  /* do something after ... */
}



/* your calling code */

#include "wrap_library.h"

wrap_fun();

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of HappyCactus
HappyCactus
Flag of Italy image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of KrzysztofRosinski

ASKER

Yep, this solution is correct, I finally did it yesterday evning and it is exacely what I need.
Thanks Guys.