cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
gsanson
Participant
Participant
10,374 Views
Registered: ‎04-13-2015

Can't compile shm_open()

Jump to solution

Hi,

 

I'm trying to use mmap and shared memory to trasnfer lots of data out the GigE port.

When I try to compile the following line I don't get errors per se but the compile has errors (build.log attached)

 

memfd = shm_open("/dev/mem", O_RDWR, 0777);

 

Doing a standard open("/dev/mem", O_RDWR); compiles just fine and if i leave a parameter out of the call the compiler properly posts an error indicating that the prototype differs from the source.

 

Does anyone know why the copiler is having issues with the shm_open ?

 

Regards,

Gary

0 Kudos
1 Solution

Accepted Solutions
rfs613
Scholar
Scholar
16,721 Views
Registered: ‎05-28-2013

To compile with the shm_open function, you must link with -lrt, otherwise you will get an undefined reference to shm_open error from the compiler. I presume that is the error you are referring to.

 

The build.log shows a number of other warnings as well, that can be fixed by adding the appropriate #include, and by ensuring that your variables are initialized before use, etc.

 

Note that open("/dev/mem") is a very different operation than shm_open("/something"). The former can only be done as root, and gives you acess to the physical memory space of the CPU. This can be used to access peripheral registers and the OCM memory.

 

In contrast, shm_open() merely creates a shared memory object. It is located in tmpfs virtual file system, using the name specified. Just like malloc() there is no control over the physical addressing, you just get a piece of memory that you can use. The filename provided acts as a label, so that multiple processess can access the same shared memory region. It is not a filename in the same sense of /dev/mem or /bin or /usr/bin.

 

Cheers,

R.

View solution in original post

0 Kudos
1 Reply
rfs613
Scholar
Scholar
16,722 Views
Registered: ‎05-28-2013

To compile with the shm_open function, you must link with -lrt, otherwise you will get an undefined reference to shm_open error from the compiler. I presume that is the error you are referring to.

 

The build.log shows a number of other warnings as well, that can be fixed by adding the appropriate #include, and by ensuring that your variables are initialized before use, etc.

 

Note that open("/dev/mem") is a very different operation than shm_open("/something"). The former can only be done as root, and gives you acess to the physical memory space of the CPU. This can be used to access peripheral registers and the OCM memory.

 

In contrast, shm_open() merely creates a shared memory object. It is located in tmpfs virtual file system, using the name specified. Just like malloc() there is no control over the physical addressing, you just get a piece of memory that you can use. The filename provided acts as a label, so that multiple processess can access the same shared memory region. It is not a filename in the same sense of /dev/mem or /bin or /usr/bin.

 

Cheers,

R.

View solution in original post

0 Kudos