[C++/Unix] undefined reference to symbol 'shm_unlink@@GLIBC_
От: xobotik Россия  
Дата: 08.09.14 07:49
Оценка:
Всем привет!

Подскажите пожалуйста как лечится: undefined reference to symbol 'shm_unlink@@GLIBC_2.2.5'.
В следующем коде (для межпроцессного взаимодействия) использую shm_open и shm_unlink.

#ifndef MEMORYMAPPEDUNIX_H
#define MEMORYMAPPEDUNIX_H

#include "MemoryMappedBase.h"

#include <stdio.h>
#include <string.h>
#include <fcntl.h>
#include <errno.h>
#include <stdlib.h>
#include <unistd.h>
#include <limits.h>
#include <sys/mman.h>
#include <iostream>

class MemoryMappedUnix : public MemoryMappedBase
{
private:
    int32_t _fd;
    const char *_key;
    bool _errorPrint;
public:
    MemoryMappedUnix(bool errorPrint = false);
    virtual ~MemoryMappedUnix();
    virtual bool TryOpen(const char *key, const uint32_t memorySize);
    virtual void Close();
    virtual void *GetData();
private:
    void Zeroing();
    void ErrorPrint();
};
#endif // MEMORYMAPPEDUNIX_H

MemoryMappedUnix::MemoryMappedUnix(bool errorPrint) : _errorPrint(errorPrint)
{
    Zeroing();
}
MemoryMappedUnix::~MemoryMappedUnix()
{
    Close();
    Zeroing();
}
bool MemoryMappedUnix::TryOpen(const char *key, const uint32_t memorySize)
{
    _key = key;
    if ((_fd = shm_open(_key, O_RDWR | O_CREAT | O_EXCL, 0777)) == -1) {
        if ((_fd = shm_open(_key, O_RDWR, 0777)) == -1) {
            ErrorPrint();
            return false;
        }
    }
    
    if (ftruncate(_fd, memorySize) == -1) {
        ErrorPrint();
        return false;
    }

    if ((_mappedView = mmap(0, memorySize, PROT_READ | PROT_WRITE, MAP_SHARED, _fd, 0)) == MAP_FAILED) {
        ErrorPrint();
        return false;
    }
    return true;
}
void MemoryMappedUnix::Close()
{
    if (close(_fd) < 0) {
        ErrorPrint();
    }
    if (shm_unlink(_key) < 0) {
        ErrorPrint();
    }
}
void *MemoryMappedUnix::GetData()
{
    return _mappedView;
}
void MemoryMappedUnix::Zeroing()
{
    _mappedView = nullptr;
    _key = nullptr;
    _errorPrint = false;
}
void MemoryMappedUnix::ErrorPrint()
{
    if (_errorPrint) {
        std::cout << " " << strerror(errno) << std::endl;
    }
}
IMemoryMapped *IMemoryMapped::Create()
{
    return new MemoryMappedUnix;
}
void IMemoryMapped::Destroy(IMemoryMapped *memoryMapped)
{
    memoryMapped->Close();
    delete memoryMapped;
}

Ошибки:
:-1: error: /home/root/Projects/PreViewer/Project/PreViewer/../../../PreViewerLib/Project/Debug32Unix//libPreViewerLib.a(MemoryMappedUnix.o): 
undefined reference to symbol 'shm_unlink@@GLIBC_2.2.5'

:-1: error: note: 'shm_unlink@@GLIBC_2.2.5' is defined in DSO /lib64/librt.so.1 so try adding it to the linker command line

/lib64/librt.so.1:-1: error: could not read symbols: Invalid operation

:-1: error: collect2: error: ld returned 1 exit status

Заранее спасибо!
С уважением!
Отредактировано 08.09.2014 7:57 xobotik . Предыдущая версия . Еще …
Отредактировано 08.09.2014 7:51 xobotik . Предыдущая версия .
 
Подождите ...
Wait...
Пока на собственное сообщение не было ответов, его можно удалить.