Kishore Chilakala
Kishore Chilakala

Reputation: 316

Linux Shared Library

I am very new to linux Application Development.

I have two libraries shared libraries libGetData.so and libProcessData.so.

And I am Running two Different C++ Applications as A and B,on a Linux PC and using these two libraries in both applications.

I have few static variables in both libraries.

But, When I set a static variable in libGetData.so library from Application A. Its is not reflecting in Application B.

My goal is if I use a shared library in any Application and if I set any static variable in that library. Same thing should reflect on an-other application which is using same library.

Please help me...

Upvotes: 2

Views: 176

Answers (1)

Jonathan Wakely
Jonathan Wakely

Reputation: 171253

But, When I set a static variable in libGetData.so library from Application A. Its is not reflecting in Application B.

Correct.

My goal is if I use a shared library in any Application and if I set any static variable in that library. Same thing should reflect on an-other application which is using same library.

No, that's not how shared libraries work.

Shared libraries allow the non-changing parts of the library to be shared by multiple processes, but that's purely an implementation detail at the OS level. They do not mean the processes share an address space. Variables in different processes are distinct and not shared.

To have the processes communicate they need to use some form of Inter-Process Communication (IPC) such as pipes, or sockets, or shared memory (which is unrelated to shared libraries).

Upvotes: 5

Related Questions