tags:

views:

78

answers:

2

how to have a shared variable in library across all application in linux (c++)?

+3  A: 

You can use POSIX shared memory to create a shared memory segment, and place the variable there. You will need to synchronise access to the shared variable using POSIX semaphores.

See the shm_overview(7) and sem_overview(7) man pages to get started.

caf
A: 

Likewise, you can use posix shared memory or just mmap() a file and have the variable exist in that area of memory.

The loader will not automatically do this with a special section such as the "shared" one in Win32 DLLs. This is probably not a big deal as it's a bit of an anti-feature anyway.

MarkR