boost 1_43_0 在arm-linux下编译

下载
1 boost_1_43_0.tar.gz
2 tar -zxvf boost_1_43_0.tar.gz
3 设置环境变量

export PATH=$PATH:/opt/timesys/toolchains/armv5l-linux/bin/

3. 进入目录执行./bootstrap.sh, 此时形成bjam文件和project-config.jam
4. 编辑project-config.jam, 仅修改using gcc这行。因为我使用的是arm-linux-gcc,所以将其改以下即可:
     using gcc : : arm51v-linux-gcc ;
5. 执行./bjam stage,编译asio
./bjam --with-system --with-thread --with-date_time --with-regex --with-serialization stage
6. 形成的静态和动态库文件就在stage目录下.
如果全部编译会如下:
    - chrono                   : building
    - date_time                : building
    - exception                : building
    - filesystem               : building
    - graph                    : building
    - graph_parallel           : building
    - iostreams                : building
    - locale                   : building
    - math                     : building
    - mpi                      : building
    - program_options          : building
    - python                   : not building
    - random                   : building
    - regex                    : building
    - serialization            : building
    - signals                  : building
    - system                   : building
    - test                     : building
    - thread                   : building
    - timer                    : building
    - wave                     : building

7 使用:
vi boost_test.cpp 敲入串口代码
编译:
arm-linux-g++ -g boost_test.cpp -I/home/neo/tools/boost-1.4 -L/home/neo/tools/boost-1.4/stage/lib/ -lboost_system -lboost_thread -lboost_chrono -lboost_wserialization -lpthread
/home/neo/tools/boost-1.4

在PC Linux上执行命令:arm-linux-readelf  -a "your binary" | grep "Shared"

 0x00000001 (NEEDED)                     Shared library: [libstdc++.so.6]
 0x00000001 (NEEDED)                     Shared library: [libm.so.6]
 0x00000001 (NEEDED)                     Shared library: [libgcc_s.so.1]
 0x00000001 (NEEDED)                     Shared library: [libc.so.6]

#include <stdio.h>
#include <boost/asio.hpp>
#include <boost/bind.hpp>

using namespace boost::asio;

int main()
{
        io_service iosev;
        // 串口COM1, Linux下为“/dev/ttyS0”
        serial_port sp(iosev, "/dev/ttyS4");
        // 设置参数
        sp.set_option(serial_port::baud_rate(9600));
                    sp.set_option(serial_port::flow_control(serial_port::flow_control::none));
        sp.set_option(serial_port::parity(serial_port::parity::none));
        sp.set_option(serial_port::stop_bits(serial_port::stop_bits::one));
        sp.set_option(serial_port::character_size(8));
        // 向串口写数据
        // 0C 02 00 20 00 08 79 1B
        //0C,02,00,20,00,08,79,1B
        unsigned char msg[] = {0x0c,0x02,0x00,0x20,0x00,0x08,0x79,0x1B};
        write(sp, buffer(msg, 8));
        // 向串口读数据
        printf("begin recv data \n");
        unsigned char buf[2];
        read(sp, buffer(buf));
        int i = 0;
        //printf("recv data:%s \n",buf);
        for(i=0;i<2;i++){
                printf("recv data:%d \n",buf[i]);
        }
        iosev.run();
        return 0;
}

你可能感兴趣的:(thread,exception,serialization,Graph,character,library)