首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >使用boost::interprocess编译链接器时出错

使用boost::interprocess编译链接器时出错
EN

Stack Overflow用户
提问于 2012-05-11 02:39:36
回答 1查看 4.6K关注 0票数 3

我已经编写了一个小程序,它将一个boost::interprocess::container字符串写入到一个共享内存中,并从其中读取另一个字符串。

我收到以下链接器错误:

代码语言:javascript
复制
g++ SharedMemTest.cpp -L /usr/lib/x86_64-linux-gnu/librt.a
/tmp/cc5v7WKj.o: In function `boost::interprocess::detail::mutexattr_wrapper::mutexattr_wrapper(bool)':
SharedMemTest.cpp:(.text._ZN5boost12interprocess6detail17mutexattr_wrapperC2Eb[_ZN5boost12interprocess6detail17mutexattr_wrapperC5Eb]+0x1c): undefined reference to `pthread_mutexattr_init'
SharedMemTest.cpp:(.text._ZN5boost12interprocess6detail17mutexattr_wrapperC2Eb[_ZN5boost12interprocess6detail17mutexattr_wrapperC5Eb]+0x31): undefined reference to `pthread_mutexattr_setpshared'
SharedMemTest.cpp:(.text._ZN5boost12interprocess6detail17mutexattr_wrapperC2Eb[_ZN5boost12interprocess6detail17mutexattr_wrapperC5Eb]+0x4c): undefined reference to `pthread_mutexattr_settype'
/tmp/cc5v7WKj.o: In function `boost::interprocess::detail::mutexattr_wrapper::~mutexattr_wrapper()':
SharedMemTest.cpp:(.text._ZN5boost12interprocess6detail17mutexattr_wrapperD2Ev[_ZN5boost12interprocess6detail17mutexattr_wrapperD5Ev]+0x14): undefined reference to `pthread_mutexattr_destroy'
/tmp/cc5v7WKj.o: In function `boost::interprocess::shared_memory_object::priv_open_or_create(boost::interprocess::detail::create_enum_t, char const*, boost::interprocess::mode_t, boost::interprocess::permissions const&)':
SharedMemTest.cpp:(.text._ZN5boost12interprocess20shared_memory_object19priv_open_or_createENS0_6detail13create_enum_tEPKcNS0_6mode_tERKNS0_11permissionsE[boost::interprocess::shared_memory_object::priv_open_or_create(boost::interprocess::detail::create_enum_t, char const*, boost::interprocess::mode_t, boost::interprocess::permissions const&)]+0xe0): undefined reference to `shm_open'
SharedMemTest.cpp:(.text._ZN5boost12interprocess20shared_memory_object19priv_open_or_createENS0_6detail13create_enum_tEPKcNS0_6mode_tERKNS0_11permissionsE[boost::interprocess::shared_memory_object::priv_open_or_create(boost::interprocess::detail::create_enum_t, char const*, boost::interprocess::mode_t, boost::interprocess::permissions const&)]+0x116): undefined reference to `shm_open'
SharedMemTest.cpp:(.text._ZN5boost12interprocess20shared_memory_object19priv_open_or_createENS0_6detail13create_enum_tEPKcNS0_6mode_tERKNS0_11permissionsE[boost::interprocess::shared_memory_object::priv_open_or_create(boost::interprocess::detail::create_enum_t, char const*, boost::interprocess::mode_t, boost::interprocess::permissions const&)]+0x16c): undefined reference to `shm_open'
SharedMemTest.cpp:(.text._ZN5boost12interprocess20shared_memory_object19priv_open_or_createENS0_6detail13create_enum_tEPKcNS0_6mode_tERKNS0_11permissionsE[boost::interprocess::shared_memory_object::priv_open_or_create(boost::interprocess::detail::create_enum_t, char const*, boost::interprocess::mode_t, boost::interprocess::permissions const&)]+0x1c0): undefined reference to `shm_open'
/tmp/cc5v7WKj.o: In function `boost::interprocess::shared_memory_object::remove(char const*)':
SharedMemTest.cpp:(.text._ZN5boost12interprocess20shared_memory_object6removeEPKc[boost::interprocess::shared_memory_object::remove(char const*)]+0x40): undefined reference to `shm_unlink'

我还尝试链接到以下内容:

代码语言:javascript
复制
g++ -c SharedMemTest.cpp
g++ -L /usr/lib/x86_64-linux-gnu/librt.a SharedMemTest.o -o SharedMemTest

但是这些命令都不起作用。谁能告诉我怎样才能编译这个简单的例子?

EN

回答 1

Stack Overflow用户

发布于 2012-05-20 22:26:16

-L的参数应该是一个目录,但是您在它后面放置了一个库文件名。你可能指的是-l rt。其他人已经建议使用-l pthread,您也可以使用-pthread链接到pthreads库。

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/10540276

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档