Review your favorite Linux distribution.
Go Back > Forums > Non-*NIX Forums > Programming
User Name
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.


  Search this Thread
Old 03-22-2006, 06:17 AM   #1
LQ Newbie
Registered: Mar 2006
Posts: 1

Rep: Reputation: 0
Question Shared variables (between ELF executables)


I want a variable to be shared between several ELF executables in the same process image - e.g. different .so files and the program executable.

And I don't want the value of the variable to be just copied between the executables (this is currently what happens for me) - i want all references to the variable in all executables to be dynamically linked against the same memory-location in a .so file.

What is the soulution? Some command-line argument to ls? Some change in the linker script? Something with the __attribute__ stuff?

Please HELP (thank you)!
Old 03-22-2006, 03:20 PM   #2
LQ Guru
Registered: Mar 2004
Distribution: SusE 8.2
Posts: 5,863
Blog Entries: 1

Rep: Reputation: Disabled
*nix shared libraries don't work like that. The code is shared - the data is always copied.

If you want shared data - you get to create a shared memory segment.

Then synchronize access to that shared memory segment.

If you're only talking about one PROGRAM (one "process") - then just declare a global variable.

The variable will be "global" in exactly one place (in your program or in one of the .so's: it doesn't matter) and it will be "extern" everywhere else.

Last edited by paulsm4; 03-22-2006 at 03:22 PM.


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
how can i move this folder of music from /root/Shared to /home/coffee/Shared ? thx mr_coffee Linux - Newbie 9 01-23-2006 07:50 AM
shared libraries, dlopen and static member variables? (C/C++) Thinking Programming 2 12-19-2005 01:55 AM
Threads synchronisation problem (mutex variables and contitional variables) zahadumy Programming 6 12-07-2005 01:30 PM
/usr/libexec/ Shared object "" not found lxxy *BSD 1 12-04-2003 01:01 PM
Shel scripting: variables pointing to variables and case Dark_Helmet Programming 5 06-08-2003 12:07 PM > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 11:53 AM.

Main Menu
Write for LQ is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration