2020/10/27

programming with Boost library,

在 ubuntu 系統中使用 boost library
首先要安裝 boost dev library: libboost-all-dev

然後分為:

只有用到 boost 的 header: boostlambda.cpp
#include <boost/lambda/lambda.hpp>
#include <iostream>
#include <iterator>
#include <algorithm>

int main()
{
    using namespace boost::lambda;
    typedef std::istream_iterator<int> in;

    std::for_each(
        in(std::cin), in(), std::cout << (_1 * 3) << " " );
}
這樣build command 就不用特別加什麼:
g++ boostlambda.cpp

如果包含 library,以這個例子,用到 boost_regex : boostregex.cpp
#include <boost/regex.hpp>
#include <iostream>
#include <string>

int main()
{
    std::string line;
    boost::regex pat( "^Subject: (Re: |Aw: )*(.*)" );

    while (std::cin)
    {
        std::getline(std::cin, line);
        boost::smatch matches;
        if (boost::regex_match(line, matches, pat))
            std::cout << matches[2] << std::endl;
    }
}
這樣 build command 就要加上 boost library
g++ boostregex.cpp -lboost_regex



如果是要 cross build for embedded.列如 for arm.
先 cross build boost library,假設build 好都放在 /dm1lib/ (include & lib)

compiple 就只要指定 additional include path (-I)和 additional libary path (-L)就可以...
aarch64-linux-gnu-g++ fexist.cpp -I/dm1lib/include -lboost_system -lboost_filesystem -L/dm1lib/lib

沒有留言:

張貼留言