开发者

variable value used by more then one shared library

开发者 https://www.devze.com 2023-03-12 16:12 出处:网络
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开发者_JS百科 varia

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开发者_JS百科 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


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消