对 'shm_open' 的未定义引用已经使用 -L /lib -lrt -lpthread

undefined reference to `shm_open' already with -L /lib -lrt -lpthread

本文关键字:-lrt -lpthread lib 引用 shm open 未定义      更新时间:2023-10-16

我只是想使用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