Hi,
I am using boost interprocess library for loading the data into map . And reading the same map with another program.I am benchmarking
the code given on the following lilnk.
http://www.boost.org/doc/libs/1_38_0/doc/html/interproc/quick_guide.html#int...
#include
#include
#include
#include <functional>
#include <utility>
int main ()
{
using namespace boost::interprocess;
//Shared memory front-end that is able to construct objects
//associated with a c-string. Erase previous shared memory with the name
//to be used and create the memory segment at the specified address and
initialize resources
shared_memory_object::remove("MySharedMemory");
try{
managed_shared_memory segment
(create_only
,"MySharedMemory" //segment name
,65536); //segment size in bytes
//Note that map's value_type is std::pair,
//so the allocator must allocate that pair.
typedef int KeyType;
typedef float MappedType;
typedef std::pair ValueType;
//Alias an STL compatible allocator of for the map.
//This allocator will allow to place containers
//in managed shared memory segments
typedef allocator
ShmemAllocator;
//Alias a map of ints that uses the previous STL-like allocator.
//Note that the third parameter argument is the ordering function
//of the map, just like with std::map, used to compare the keys.
typedef map
MyMap;
//Initialize the shared memory STL-compatible allocator
ShmemAllocator alloc_inst (segment.get_segment_manager());
//Construct a shared memory map.
//Note that the first parameter is the comparison function,
//and the second one the allocator.
//This the same signature as std::map's constructor taking an
allocator
MyMap *mymap =
segment.construct<MyMap>("MyMap") //object name
(std::less<int>() //first ctor
parameter
,alloc_inst); //second ctor
parameter
//Insert data in the map
for(int i = 0; i < 100; ++i){
mymap->insert(std::pair(i, (float)i));
}
}
catch(...){
shared_memory_object::remove("MySharedMemory");
throw;
}
shared_memory_object::remove("MySharedMemory");
return 0;
}
but getting the following errors.
manish@user-desktop:~/Desktop$ g++ memorymap.cpp
/tmp/ccmOQCB8.o: In function
`boost::interprocess::shared_memory_object::priv_open_or_create(boost::interprocess::detail::create_enum_t,
char const*, boost::interprocess::mode_t)':
memorymap.cpp:(.text._ZN5boost12interprocess20shared_memory_object19priv_open_or_createENS0_6detail13create_enum_tEPKcNS0_6mode_tE[boost::interprocess::shared_memory_object::priv_open_or_create(boost::interprocess::detail::create_enum_t,
char const*, boost::interprocess::mode_t)]+0x163): undefined reference to
`shm_open'
/tmp/ccmOQCB8.o: In function
`boost::interprocess::detail::mutexattr_wrapper::mutexattr_wrapper(bool)':
memorymap.cpp:(.text._ZN5boost12interprocess6detail17mutexattr_wrapperC1Eb[boost::interprocess::detail::mutexattr_wrapper::mutexattr_wrapper(bool)]+0x14):
undefined reference to `pthread_mutexattr_init'
memorymap.cpp:(.text._ZN5boost12interprocess6detail17mutexattr_wrapperC1Eb[boost::interprocess::detail::mutexattr_wrapper::mutexattr_wrapper(bool)]+0x2b):
undefined reference to `pthread_mutexattr_setpshared'
memorymap.cpp:(.text._ZN5boost12interprocess6detail17mutexattr_wrapperC1Eb[boost::interprocess::detail::mutexattr_wrapper::mutexattr_wrapper(bool)]+0x4d):
undefined reference to `pthread_mutexattr_settype'
/tmp/ccmOQCB8.o: In function
`boost::interprocess::detail::mutexattr_wrapper::~mutexattr_wrapper()':
memorymap.cpp:(.text._ZN5boost12interprocess6detail17mutexattr_wrapperD1Ev[boost::interprocess::detail::mutexattr_wrapper::~mutexattr_wrapper()]+0xd):
undefined reference to `pthread_mutexattr_destroy'
/tmp/ccmOQCB8.o: In function
`boost::interprocess::shared_memory_object::remove(char const*)':
memorymap.cpp:(.text._ZN5boost12interprocess20shared_memory_object6removeEPKc[boost::interprocess::shared_memory_object::remove(char
const*)]+0x33): undefined reference to `shm_unlink'
collect2: ld returned 1 exit stats.
What is the reason for this pblm? Thanks in advance.
Regards
Manish
--
View this message in context: http://www.nabble.com/How-to-use-interprocess-communication-to-load-the-data...
Sent from the Boost - Users mailing list archive at Nabble.com.