简体   繁体   English

-L / lib -lrt -lpthread已经对`shm_open'进行了未定义的引用

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

I just want to use the boost library to create a shared memory on an ARM system. 我只想使用boost库在ARM系统上创建共享内存。 It work fine if you want to compile it only under ubuntu. 如果只想在ubuntu下编译它,它将很好地工作。 However, when I want to cross compile it with TI's CCSv6 and angstrom toolchain, it keep pushing errors. 但是,当我想与TI的CCSv6和埃工具链进行交叉编译时,它会不断出错。

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 / include -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 to shm_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 to shm_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: undefined reference to未定义引用/usr/include/boost/interprocess/shared_memory_object.hpp:315:对shm_open' /usr/include/boost/interprocess/shared_memory_object.hpp:315: undefined reference to / 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' /usr/include/boost/interprocess/shared_memory_object.hpp:334: undefined reference toshm_open' /usr/include/boost/interprocess/shared_memory_object.hpp:334: undefined reference to collect2:ld返回1退出状态make:*** [测试]错误1

undefined reference to shm_open' means it cannot find -lrt for ARM. undefined reference to 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. 在构建命令行中,您需要指定ARM构建库的包含和库路径,而不是Ubuntu库的路径。 So -I/usr/include and -L /lib is wrong. 因此-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. 另外,您还需要为ARM构建的boost,尽管如果您只想使用进程间库,那么boost标头就足够了。 But you need to copy them into different location because including them from /usr/include includes also other headers specific to Ubuntu. 但是您需要将它们复制到其他位置,因为从/usr/include包含它们/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 . 您可以使用您提到的交叉编译器IDE或可以通过以下方式安装的arm g ++交叉编译器: sudo apt-get install g++-arm-linux-gnueabihf Some headers and libraries for ARM will be installed too. 一些用于ARM的标头和库也将安装。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM