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]
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
点击(此处)折叠或打开
- //
- // blocking_tcp_echo_server.cpp
- // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~
- //
- // Copyright (c) 2003-2011 Christopher M. Kohlhoff (chris at kohlhoff dot com)
- //
- // Distributed under the Boost Software License, Version 1.0. (See accompanying
- // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
- //
- #include <cstdlib>
- #include <iostream>
- #include <boost/bind.hpp>
- #include <boost/smart_ptr.hpp>
- #include <boost/asio.hpp>
- #include <boost/thread.hpp>
- using boost::asio::ip::tcp;
- const int max_length = 1024;
- typedef boost::shared_ptr<tcp::socket> socket_ptr;
- void session(socket_ptr sock)
- {
- try
- {
- for (;;)
- {
- char data[max_length];
- boost::system::error_code error;
- size_t length = sock->read_some(boost::asio::buffer(data), error);
- if (error == boost::asio::error::eof)
- break; // Connection closed cleanly by peer.
- else if (error)
- throw boost::system::system_error(error); // Some other error.
- boost::asio::write(*sock, boost::asio::buffer(data, length));
- }
- }
- catch (std::exception& e)
- {
- std::cerr << "Exception in thread: " << e.what() << "\n";
- }
- }
- void server(boost::asio::io_service& io_service, short port)
- {
- tcp::acceptor a(io_service, tcp::endpoint(tcp::v4(), port));
- for (;;)
- {
- socket_ptr sock(new tcp::socket(io_service));
- a.accept(*sock);
- boost::thread t(boost::bind(session, sock));
- }
- }
- int main(int argc, char* argv[])
- {
- boost::asio::io_service io_service;
- using namespace std; // For atoi.
- server(io_service, atoi(argv[1]));
- return 0;
- }
注意一点是需要将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
开启四个客户端程序