boost 1.51.0移植到ARM S3C6410成功运行

http://blog.chinaunix.net/uid-8048969-id-3374823.html

OS       :Fedora 13 
Boost Ver: 1.51.0
Compiler : GNU gcc 4.3.2 for ARM 

[root@localhost Release]# arm-linux-gcc -v
Using built-in specs.
Target: arm-none-linux-gnueabi
Configured with: /scratch/julian/lite-respin/linux/src/gcc-4.3/configure --build=i686-pc-linux-gnu --host=i686-pc-linux-gnu --target=arm-none-linux-gnueabi --enable-threads --disable-libmudflap --disable-libssp --disable-libstdcxx-pch --with-gnu-as --with-gnu-ld --enable-languages=c,c++ --enable-shared --enable-symvers=gnu --enable-__cxa_atexit --with-pkgversion='Sourcery G++ Lite 2008q3-72' --with-bugurl=https://support.codesourcery.com/GNUToolchain/ --disable-nls --prefix=/opt/codesourcery --with-sysroot=/opt/codesourcery/arm-none-linux-gnueabi/libc --with-build-sysroot=/scratch/julian/lite-respin/linux/install/arm-none-linux-gnueabi/libc --with-gmp=/scratch/julian/lite-respin/linux/obj/host-libs-2008q3-72-arm-none-linux-gnueabi-i686-pc-linux-gnu/usr --with-mpfr=/scratch/julian/lite-respin/linux/obj/host-libs-2008q3-72-arm-none-linux-gnueabi-i686-pc-linux-gnu/usr --disable-libgomp --enable-poison-system-directories --with-build-time-tools=/scratch/julian/lite-respin/linux/install/arm-none-linux-gnueabi/bin --with-build-time-tools=/scratch/julian/lite-respin/linux/install/arm-none-linux-gnueabi/bin
Thread model: posix
gcc version 4.3.2 (Sourcery G++ Lite 2008q3-72) 
[root@localhost Release]

1. 确保ARM编译成功安装,并配置好环境变量。 
2. 解压boost压缩包 
3. 进入目录执行./bootstrap.sh, 此时形成bjam文件和project-config.jam 
4. 编辑project-config.jam, 仅修改using gcc这行。因为我使用的是arm-linux-gcc,所以将其改以下即可: 
     using gcc : : arm-linux-gcc ; 
5. 执行./bjam stage, ok大功告成. 
6. 形成的静态和动态库文件就在stage目录下.

在得到boost 库后,把所需要的库放在ARM linux文件系统
我把其中的chrono system thread库放进去,并将其中boost的一个例程交叉编译运行 blocking_tcp_echo_server.cpp

点击(此处)折叠或打开

  1. //
  2. // blocking_tcp_echo_server.cpp
  3. // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  4. //
  5. // Copyright (c) 2003-2011 Christopher M. Kohlhoff (chris at kohlhoff dot com)
  6. //
  7. // Distributed under the Boost Software License, Version 1.0. (See accompanying
  8. // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
  9. //

  10. #include <cstdlib>
  11. #include <iostream>
  12. #include <boost/bind.hpp>
  13. #include <boost/smart_ptr.hpp>
  14. #include <boost/asio.hpp>
  15. #include <boost/thread.hpp>

  16. using boost::asio::ip::tcp;

  17. const int max_length = 1024;

  18. typedef boost::shared_ptr<tcp::socket> socket_ptr;

  19. void session(socket_ptr sock)
  20. {
  21.   try
  22.   {
  23.     for (;;)
  24.     {
  25.       char data[max_length];

  26.       boost::system::error_code error;
  27.       size_t length = sock->read_some(boost::asio::buffer(data), error);
  28.       if (error == boost::asio::error::eof)
  29.         break; // Connection closed cleanly by peer.
  30.       else if (error)
  31.         throw boost::system::system_error(error); // Some other error.

  32.       boost::asio::write(*sock, boost::asio::buffer(data, length));
  33.     }
  34.   }
  35.   catch (std::exception& e)
  36.   {
  37.     std::cerr << "Exception in thread: " << e.what() << "\n";
  38.   }
  39. }

  40. void server(boost::asio::io_service& io_service, short port)
  41. {
  42.   tcp::acceptor a(io_service, tcp::endpoint(tcp::v4(), port));
  43.   for (;;)
  44.   {
  45.     socket_ptr sock(new tcp::socket(io_service));
  46.     a.accept(*sock);
  47.     boost::thread t(boost::bind(session, sock));
  48.   }
  49. }

  50. int main(int argc, char* argv[])
  51. {


  52.     boost::asio::io_service io_service;

  53.     using namespace std; // For atoi.
  54.     server(io_service, atoi(argv[1]));

  55.   return 0;
  56. }
使用eclipse建立工程,并配置为arm-linux-g++编译
注意一点是需要将arm交叉编译的库的路径给正确加上
执行后结果发现库没找到
./boost_server 
./boost_server: error while loading shared libraries: libboost_chrono.so.1.51.0: cannot open shared object file: No such file or directory
于是下载到arm平台再次执行测试
在arm linux中添加的库有下图
执行命令,端口号为2222
./boost_server 2222
开启四个客户端程序

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值