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

时间:2022-09-26 20:36:29

I just want to use the boost library to create a shared memory on an ARM system. It work fine if you want to compile it only under ubuntu. However, when I want to cross compile it with TI's CCSv6 and angstrom toolchain, it keep pushing errors.

我只想使用boost库在ARM系统上创建共享内存。如果你只想在ubuntu下编译它,它就会运行得很好。但是,当我想用TI的CCSv6和angstrom工具链交叉编译它时,它会不断地推入错误。

Because I do not know how to write a makefile for cross compile, I think using TI their own IDE might be a good choice to avoid further problems.

因为我不知道如何编写一个用于交叉编译的makefile,我认为使用TI自己的IDE可能是避免进一步问题的好选择。

Here is my code and print out of build console.

这是我的代码并打印出构建控制台。

#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 -O0 -g3 -Wall -c -fmessage-length=0 -L /lib -lrt -lpthread -fPIC

g++ -std=c++0x -I/usr/包含-O0 -g3 -Wall -c -fmessage-length=0 -L /lib -lrt -lpthread -fPIC

The IDE called Code Composer Studio has cross compile settings as below:

称为Code Composer Studio的IDE具有如下交叉编译设置:

Prefix: arm-angstrom-linux-gnueabi-

前缀:arm-angstrom-linux-gnueabi -

Path: /usr/local/oecore-x86_64/sysroots/x86_64-angstromsdk-linux/usr/bin/armv5te-angstrom-linux-gnueabi

路径:/usr/local/oecore-x86_64 / sysroots x86_64-angstromsdk-linux / usr / bin / armv5te-angstrom-linux-gnueabi

Build Console:

建立控制台:

/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 toshm_open' /usr/include/boost/interprocess/shared_memory_object.hpp:327: undefined reference to shm_open' /usr/include/boost/interprocess/shared_memory_object.hpp:334: undefined reference toshm_open' collect2: ld returned 1 exit status make: *** [test] Error 1

/usr/include/boost/interprocess / shared_memory_object。hpp:309: shm_open /usr/include/boost/interprocess/shared_memory_object的未定义引用。hpp:315:未定义的shm_open的引用/usr/include/boost/interprocess/shared_memory_object。hpp:327: shm_open /usr/include/boost/interprocess/shared_memory_object的未定义引用。hpp:334:未定义引用shm_open' collect2: ld返回1退出状态make: *** [test] Error 1

1 个解决方案

#1


0  

undefined reference to shm_open' means it cannot find -lrt for ARM.

未定义的shm_open的引用意味着它找不到ARM的-lrt。

In your build command line you need to specify include and library paths to ARM built libraries, not to Ubuntu ones. So -I/usr/include and -L /lib is wrong.

在构建命令行中,您需要指定包含和库路径来辅助构建库,而不是Ubuntu类库。所以-I/usr/include和-L /lib是错误的。

Also you need boost built for ARM, although if you just want to use interprocess library then boost headers should be enough. But you need to copy them into different location because including them from /usr/include includes also other headers specific to Ubuntu.

此外,您还需要为ARM构建boost,尽管如果您只想使用进程间库,那么boost头文件应该足够了。但是您需要将它们复制到不同的位置,因为包括从/usr/include中包含的其他特定于Ubuntu的头。

You can use the cross compiler IDE you mentioned or arm g++ cross compiler which you can install by: sudo apt-get install g++-arm-linux-gnueabihf. Some headers and libraries for ARM will be installed too.

您可以使用您提到的交叉编译器IDE或可以通过:sudo apt-get install g+ -arm-linux-gnueabihf安装的arm g++交叉编译器。还将安装一些ARM的头文件和库。

#1


0  

undefined reference to shm_open' means it cannot find -lrt for ARM.

未定义的shm_open的引用意味着它找不到ARM的-lrt。

In your build command line you need to specify include and library paths to ARM built libraries, not to Ubuntu ones. So -I/usr/include and -L /lib is wrong.

在构建命令行中,您需要指定包含和库路径来辅助构建库,而不是Ubuntu类库。所以-I/usr/include和-L /lib是错误的。

Also you need boost built for ARM, although if you just want to use interprocess library then boost headers should be enough. But you need to copy them into different location because including them from /usr/include includes also other headers specific to Ubuntu.

此外,您还需要为ARM构建boost,尽管如果您只想使用进程间库,那么boost头文件应该足够了。但是您需要将它们复制到不同的位置,因为包括从/usr/include中包含的其他特定于Ubuntu的头。

You can use the cross compiler IDE you mentioned or arm g++ cross compiler which you can install by: sudo apt-get install g++-arm-linux-gnueabihf. Some headers and libraries for ARM will be installed too.

您可以使用您提到的交叉编译器IDE或可以通过:sudo apt-get install g+ -arm-linux-gnueabihf安装的arm g++交叉编译器。还将安装一些ARM的头文件和库。