boost 1_43_0 在arm-linux下編譯

來源:互聯網
上載者:User

下載
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;
}

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.