ALT Linux Community general discussions
 help / color / mirror / Atom feed
* [Comm] Пропадаю. Linux и shared memory- что я делаю не так?
@ 2008-04-01  7:59 gosha
  2008-04-01  5:01 ` Michael Holzman
  2008-04-01  6:29 ` Andrey Rahmatullin
  0 siblings, 2 replies; 4+ messages in thread
From: gosha @ 2008-04-01  7:59 UTC (permalink / raw)
  To: community

AltLinux_4 - не собираются программы, использующие shared memory- что я мог сделать не так?



/*  ====================   shm_test.c   =========================  */
#include <stdio.h>
#include <sys/mman.h>
#include <sys/stat.h>
#include <string.h>
#include <sys/types.h>
#include <fcntl.h>
 
#define SHM_NAME "/tmp/shm_car_workstantion"                                                                                                   
#define SHM_SIZE 0x1000                                                                                                                                                       
int shm_fd;                                                                                           
void* shm_addr;               /* shared memory attach address */
static float *analog;
static char *control, *sensor;
/*=================================================================================================*/
static int destroy_shared_memory(void)
{if(-1 == close(shm_fd))
    {perror("close"); return -1;}
 if (-1 == shm_unlink(SHM_NAME))
       {perror("shm_unlink"); return -1;} 
 }
/*=================================================================================================*/
int main(void)
{destroy_shared_memory();
 if((shm_fd=shm_open(SHM_NAME, O_RDWR, S_IRUSR | S_IWUSR)) >=0)
   {destroy_shared_memory();}
 shm_fd = shm_open(SHM_NAME, O_CREAT | O_RDWR, S_IRUSR | S_IWUSR);                                                      
 if(shm_fd == -1) 
  {perror("shm_open"); return -1;} 
 if (ftruncate(shm_fd, (off_t) SHM_SIZE) == -1)                                                      
    {perror("ftruncate"); destroy_shared_memory();    return -1;}
 shm_addr = mmap(NULL, (size_t)(SHM_SIZE), PROT_READ | PROT_WRITE, MAP_SHARED, shm_fd, (off_t)0);
 if(shm_addr == MAP_FAILED)
    {perror("mmap"); destroy_shared_memory(); return -1;}
 memset(shm_addr, 0, (size_t)SHM_SIZE);                                           
 analog= (float *) shm_addr + 0x100;
 sensor= (char  *) shm_addr + 0x200;
 control=(char  *) shm_addr + 0x300; 
 return 1;
} 
 /*=================================================================================================*/



#gcc shm_test.c
 
/tmp/.private/gosha/ccebTZxk.o: In function `destroy_shared_memory':
shm_test.c:(.text+0x3e): undefined reference to `shm_unlink'
/tmp/.private/gosha/ccebTZxk.o: In function `main':
shm_test.c:(.text+0x96): undefined reference to `shm_open'
shm_test.c:(.text+0xc0): undefined reference to `shm_open' 
 



в /usr/include/sys/mman.h
данные ф-ии присутствуют.

Где могла собака порыться?


Спасибо.
-- 
С Уваженим,
       gosha.


^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2008-04-01  9:47 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2008-04-01  7:59 [Comm] Пропадаю. Linux и shared memory- что я делаю не так? gosha
2008-04-01  5:01 ` Michael Holzman
2008-04-01  9:47   ` gosha
2008-04-01  6:29 ` Andrey Rahmatullin

ALT Linux Community general discussions

This inbox may be cloned and mirrored by anyone:

	git clone --mirror http://lore.altlinux.org/community/0 community/git/0.git

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V2 community community/ http://lore.altlinux.org/community \
		mandrake-russian@linuxteam.iplabs.ru community@lists.altlinux.org community@lists.altlinux.ru community@lists.altlinux.com
	public-inbox-index community

Example config snippet for mirrors.
Newsgroup available over NNTP:
	nntp://lore.altlinux.org/org.altlinux.lists.community


AGPL code for this site: git clone https://public-inbox.org/public-inbox.git