The Shed is going Social! Join us on FaceBook and Twitter and chime in on the conversation.
|
 |
|
Dev Shed Forums
> Programming Languages
> C Programming
|
Rebuild and install Shared Library
Discuss Rebuild and install Shared Library in the C Programming forum on Dev Shed. Rebuild and install Shared Library C programming forum discussing all C derivatives, including C#, C++, Object-C, and even plain old vanilla C. These languages are low level languages, and used on projects such as device drivers, compilers, and even whole computer operating systems.
|
|
 |
|
|
|
|

Dev Shed Forums Sponsor:
|
|
|

October 19th, 2010, 02:25 PM
|
|
Contributing User
|
|
Join Date: Nov 2004
Location: UK
Posts: 196
Time spent in forums: 1 Day 10 h 57 m 49 sec
Reputation Power: 9
|
|
|
Rebuild and install Shared Library
I have updated a program whih has a shared library so that other programs can access some of its data.
However these other programs are getting 0 for data items they try and access via the shared library, non zero values exist. I have deleted all the .obj files and re-compiled them, but still the same problem including the shared library code.
Are they any way to ensure that all copies/version of the old shared library are removed and that the new one is being used.
Shared memory is being used by many of these programs and I have seen a similar problems before, but re-building usually sorted it out. Note they are a few accounts in the sytems.
Any suggestions?
Andy
|

October 19th, 2010, 06:18 PM
|
|
Contributing User
|
|
Join Date: Jan 2004
Location: Constant Limbo
|
|
|
This is highly dependent on so many things you fail to mention.
What platform?
Assuming no interface changed, are the calls executing successfully - did you make provisions for when they do not?
Code would also be helpful so that we be relatively sure you haven't introduced some typo that might waste everyone's time.
__________________
True happiness is not getting what you want, it's wanting what you've already got.
My Blog
|

October 20th, 2010, 08:05 AM
|
|
Contributing User
|
|
Join Date: Nov 2004
Location: UK
Posts: 196
Time spent in forums: 1 Day 10 h 57 m 49 sec
Reputation Power: 9
|
|
Quote: | Originally Posted by L7Sqr This is highly dependent on so many things you fail to mention.
What platform?
Assuming no interface changed, are the calls executing successfully - did you make provisions for when they do not?
Code would also be helpful so that we be relatively sure you haven't introduced some typo that might waste everyone's time. |
I think the problem is with Shared Memory. The main program creates shared memory and the shared library should use this shared memory. It does a open or create on this shared memory.
My test program that uses the shared memory library returns zeros. It looks like the shared library has created a new shared memory area.
Is it the order of building the units? As two shared memeory items seem to exist with the same ID or name.
Question how to clear out the shared memory and start all over again so that only one exists!
Code:
shm_id = shmget(key, shm_size, (IPC_CREAT | IPC_EXCL | shmflg));
|

October 20th, 2010, 08:44 AM
|
|
Contributing User
|
|
Join Date: Jan 2004
Location: Constant Limbo
|
|
Zero is an appropriate return value from shmget. Is there a reason that you think that it is an error to get that?
In linux: will list the shared memory segments. You can use to remove those entries.
|

October 20th, 2010, 11:52 AM
|
|
Contributing User
|
|
Join Date: Nov 2004
Location: UK
Posts: 196
Time spent in forums: 1 Day 10 h 57 m 49 sec
Reputation Power: 9
|
|
|
Sorry the return values I get is from call using the shared library. I know a little about shared memory keys and thier association with the file system. I will try the ipcrm -m option when I get on the system.
I just wondered if any command to remove the shared library or to see the shared memory its using.
|

October 21st, 2010, 11:25 AM
|
|
Contributing User
|
|
Join Date: Nov 2004
Location: UK
Posts: 196
Time spent in forums: 1 Day 10 h 57 m 49 sec
Reputation Power: 9
|
|
My test program works some times. I am wondering if they are any settings to allow multiple access to the Shared Memory?
The code is as floows:-
Code:
SHM_EMU = (void *)shmat(shm_id, (void *)0, 0);
if (SHM_EMU == (void *)-1) {
printf("\nAttach Shared Memory Error\n");
return (void *)-1;
} else {
printf("\nAttach Shared Memory %d \n", shm_id);
return SHM_EMU;
}
The shared library just calls this routine once only.
|

October 22nd, 2010, 05:25 AM
|
 |
I'm Baaaaaaack!
|
|
Join Date: Jul 2003
Location: Maryland
|
|
|
I don't know the specifics, but there are flags that allow for multiple access to shared memory (hence the moniker 'shared'). Google will be your friend here.
|

October 22nd, 2010, 09:27 AM
|
|
Contributing User
|
|
Join Date: Jan 2004
Location: Constant Limbo
|
|
I'm still not sure of what it is you are doing outside of the context you provide, but here is a short example that works as I believe you want it to.
c Code:
Original
- c Code |
|
|
|
/* produce.c */ #include <string.h> #include <sys/shm.h> #include <sys/ipc.h> int main () { int shmid = 0, value = 42; key_t shmkey = 2; char * mem = 0; shmid = shmget (shmkey, 1024, IPC_CREAT | IPC_EXCL | SHM_R | SHM_W ); mem = shmat (shmid, 0, 0); memcpy (mem, &value, sizeof (value)); shmdt (mem); return 0; }
c Code:
Original
- c Code |
|
|
|
/* consume.c */ #include <stdio.h> #include <string.h> #include <sys/shm.h> #include <sys/ipc.h> int main () { int shmid = 0, value = 0; key_t shmkey = 2; char * mem = 0; shmid = shmget (shmkey, 1024, 0); mem = shmat (shmid, 0, 0); memcpy (&value, mem, sizeof (value)); printf ("Read '%d' from shared memory location\n", value ); shmdt (mem); shmctl (shmid, IPC_RMID, 0); return 0; }
With those you can follow with:
Code:
$ ipcs -m
------ Shared Memory Segments --------
key shmid owner perms bytes nattch status
$ ./produce
$ ipcs -m
------ Shared Memory Segments --------
key shmid owner perms bytes nattch status
0x00000002 16613385 jbrown 600 1024 0
$ ./consume
Read '42' from shared memory location
$ ipcs -m
------ Shared Memory Segments --------
key shmid owner perms bytes nattch status
My guess is that most of that is review for you if you've already been using shared memory but without a working example from you the best I can do is give you minimal working code.
N.B. All error checking has been removed in the above examples for clarity.
|
Developer Shed Advertisers and Affiliates
| Thread Tools |
Search this Thread |
|
|
|
| Display Modes |
Rate This Thread |
Linear Mode
|
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
|
|