arm交叉编译器编译boost库并调用(记录)

来源:互联网 发布:触摸屏图片展示软件 编辑:程序博客网 时间:2024/06/07 19:31


环境:ubuntu12.04 arm9 arm-none-linux-gnueabi-g++

安装:

1. 确保ARM编译成功安装,并配置好环境变量。 
2. 解压boost压缩包 
3. 进入目录执行./bootstrap.sh, 此时形成bjam文件和project-config.jam 
4. 编辑project-config.jam, 仅修改using gcc这行。因为我使用的是arm-none-linux-gnueabi-g++,所以将其改以下即可: 
     using gcc : arm  : arm-none-linux-gnueabi-g++; (注意空格)
5. 执行./bjam 或者 ./bjam stage --layout=tagged --build-type=complete  (好像是后者生成的库文件更多)
6. 形成的静态和动态库文件就在stage目录下.




调用:


test.cpp



#include <boost/thread.hpp>
#include <iostream>
void wait(int seconds)
{
boost::this_thread::sleep(boost::posix_time::seconds(seconds));
}
void thread()
{
for (int i = 0; i < 5; ++i)
{
wait(1);
std::cout << i << std::endl;
}
}
int main()
{
boost::thread t(thread);
t.join();
}

编译命令: arm-none-linux-gnueabi-g++ test.cpp -o test1  -I./ -L./stage/lib -lboost_system -lboost_thread  (当前目录就是boost的目录),然后将stage/lib下的文件放到arm上,确保所在穆培配置到了环境变量中,我放在/usr/lib中。

问题:编译成功后,将2进制文件放到arm上执行,会出现Inconsistency detected by ld.so: dl-deps.c: 622: _dl_map_object_deps: Assertion `nlist > 1' ,这是你的程序调用boost库失败,你应该把你之前用在linux上交叉编译的那些库(可根据需要)放到arm上的/usr/lib下,确保这个目录配置了环境变量即可


补充:以上只是实现的jing态编译,所以需要将boost库移植到arm上,如果使用静态编译,则只需要把运行程序放到arm上就可以直接运行。
编译命令:arm-none-linux-gnueabi-g++ -o test test.cpp -I./ ./stage/lib/libboost_thread.a -lpthread


0 0
原创粉丝点击