Reputation: 3884
I am writing an application in C which uses both user defined satically linked library(using -l option) and dynamically linked library that i preload(using ld-preload). Now I have a variable (a socket connection) that is set up from the statically linked library and the same client socket is to be used by the other shared libraries too.
How do i declare and maintain the value this client socket across libraries till the connection is exclusively broken from the calling process.
Thanks
Upvotes: 1
Views: 200
Reputation: 593
I have never done this but seems like putting:
extern int yourfileno;
into the header file for the static library should work. Declare this global variable in one of the c files for the same library.
Really this is the same as creating get/set routines in the library.
Some might consider it better practice to have the static library declare a struct definition:
typedef struct {
int fileno;
int is_opened;
...other stuf;
} StatLibType;
Then have you main program call something like:
StatLibType *statlib_new_connection();
Pass the newly created structure to the other dynaimic library so that it can use it.
Upvotes: 1