对 'shm_open' 的未定义引用已经使用 -L /lib -lrt -lpthread
undefined reference to `shm_open' already with -L /lib -lrt -lpthread
我只是想使用boost库在ARM系统上创建共享内存。如果你只想在ubuntu下编译它,它可以很好地工作。然而,当我想用TI的CCSv6和angstrom工具链交叉编译它时,它一直在推错误。
因为我不知道如何编写一个交叉编译的makefile,我认为使用TI自己的IDE可能是一个很好的选择,以避免进一步的问题。
这是我的代码和打印出来的构建控制台。
#include <boost/interprocess/shared_memory_object.hpp>
#include <boost/interprocess/mapped_region.hpp>
#include <iostream>
using namespace boost::interprocess;
int main()
{
shared_memory_object shdmem{open_or_create, "Boost1", read_write};
shdmem.truncate(1024);
mapped_region region{shdmem, read_write};
}
g++ -std=c++0x -I/usr/include - 0 -g3 -Wall -c -fmessage-length=0 -L/lib -lrt -lpthread -fPIC
Code Composer Studio的交叉编译设置如下:
前缀:arm-angstrom-linux-gnueabi -
路径:/usr/local/oecore-x86_64/sysroots x86_64-angstromsdk-linux/usr/bin/armv5te-angstrom-linux-gnueabi
建立控制台:
/usr/include/boost/interprocess/shared_memory_object.hpp:309: undefined reference to shm_open'
/usr/include/boost/interprocess/shared_memory_object.hpp:315: undefined reference to
shm_open'/usr/include/boost/interprocess/shared_memory_object.hpp:327:对shm_open'
/usr/include/boost/interprocess/shared_memory_object.hpp:334: undefined reference to
shm_open的未定义引用Collect2: ld返回1退出状态make: *** [test] Error 1
undefined reference to shm_open'
表示无法为ARM找到-lrt
在你的build命令行中,你需要指定包含和库路径到ARM构建的库,而不是Ubuntu的库。所以-I/usr/include
和-L /lib
是错误的。
你还需要为ARM构建boost,尽管如果你只想使用进程间库,那么boost头应该足够了。但是你需要将它们复制到不同的位置,因为从/usr/include
包含它们还包括其他特定于Ubuntu的头文件。
你可以使用你提到的交叉编译IDE或arm g++交叉编译器,你可以通过以下方式安装:sudo apt-get install g++-arm-linux-gnueabihf
。
- NDK R20 LD:LD:错误:找不到-lpthread
- ld:找不到 -lpthread 的库
- 人咬狗:符号在没有链接库的情况下解析?clock_gettime()-lrt
- 即使使用 lpthread 也未定义对"pthread_join"错误的引用
- -lrt选项的用途是什么
- 添加 -lrt 时跟踪编译器错误"undefined reference"不起作用
- 如何使用 G++ 与 -LRT 链接
- 如何让 cmake 使用 "-pthread" 而不是 -lpthread"?
- 使用 -lpthread、G++ 编译器错误"undefined reference to "信号量调用(如"sem_open"
- 为安卓构建带有错误"cannot find -lrt"的加速
- Boost安装失败:找不到-lrt
- AIXCMakeTest没有添加正确的-lpthread
- 我如何让qmake在链接阶段的-lpthread之后添加-lm ?
- 警告:链接器路径没有库-lpthread的实际文件
- 对 'shm_open' 的未定义引用已经使用 -L /lib -lrt -lpthread
- C++应用程序编译错误:找不到-lpthread
- 在windows上使用openmp和mingw.找不到-lpthread
- old option -lrt指的是哪个库(Bionic libc)
- solaris 10 gcc 4.8.2上的-lpthread和-phreads之间有什么区别