LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
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.

Notices


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

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


Hello!

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, 02:20 PM   #2
paulsm4
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.

PS:
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 02:22 PM.
 
  


Reply


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 06:50 AM
shared libraries, dlopen and static member variables? (C/C++) Thinking Programming 2 12-19-2005 12:55 AM
Threads synchronisation problem (mutex variables and contitional variables) zahadumy Programming 6 12-07-2005 12:30 PM
/usr/libexec/ld-elf.so.1: Shared object "libgd.so.4" not found lxxy *BSD 1 12-04-2003 12:01 PM
Shel scripting: variables pointing to variables and case Dark_Helmet Programming 5 06-08-2003 11:07 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 11:35 PM.

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