CrossPlatform/C++/boost example link to boost shared lib(32bit/x86)

99 篇文章 0 订阅
24 篇文章 0 订阅

CrossPlatform/C++/boost 32bit build/Ubuntu16_x86_64bit

Refer to https://blog.csdn.net/hushui/article/details/103387768

 

 

/**
## note libboost_thread.so/libboost_system.so are both built as intel 32bit shared lib.

lake@localhost:~/local/third-party$ g++ -I ./boost_1_51_0     -m32  my-boost-lib-thread-example.cpp   -L ./boost_1_51_0/stage/lib/   -lboost_thread   -lboost_system
In file included from ./boost_1_51_0/boost/chrono/duration.hpp:42:0,
                 from ./boost_1_51_0/boost/chrono/time_point.hpp:33,
                 from ./boost_1_51_0/boost/thread/locks.hpp:18,
                 from ./boost_1_51_0/boost/thread/pthread/mutex.hpp:12,
                 from ./boost_1_51_0/boost/thread/mutex.hpp:16,
                 from ./boost_1_51_0/boost/thread/pthread/thread_data.hpp:13,
                 from ./boost_1_51_0/boost/thread/thread.hpp:17,
                 from ./boost_1_51_0/boost/thread.hpp:13,
                 from my-boost-lib-thread-example.cpp:3:
./boost_1_51_0/boost/type_traits/common_type.hpp:70:22: warning: variadic templates only available with -std=c++11 or -std=gnu++11
     template<typename... T>
                      ^
./boost_1_51_0/boost/type_traits/common_type.hpp:150:46: warning: variadic templates only available with -std=c++11 or -std=gnu++11
     template<typename T, typename U, typename... V>
                                              ^

lake@localhost:~/local/third-party$ file a.out
a.out: ELF 32-bit LSB executable, Intel 80386, version 1 (GNU/Linux), dynamically linked, interpreter /lib/ld-, for GNU/Linux 2.6.32, BuildID[sha1]=14eb1b96c709c20e93b76fb39b725ead45cf5097, not stripped
lake@localhost:~/local/third-party$ ./a.out
./a.out: error while loading shared libraries: libboost_thread.so.1.51.0: cannot open shared object file: No such file or directory

lake@localhost:~/local/third-party$ export LD_LIBRARY_PATH=./boost_1_51_0/stage/lib/:$LD_LIBRARY_PATH
lake@localhost:~/local/third-party$ ./a.out
x= 1
thread1: 0
thread1: 1
thread1: 2
thread1: 3
thread1: 4
thread1: 5
thread1: 6
thread1: 7
thread1: 8
thread1: 9
x= 2
thread2: 0
thread2: 1
thread2: 2
thread2: 3
thread2: 4
thread2: 5
thread2: 6
thread2: 7
thread2: 8
thread2: 9
lake@localhost:~/local/third-party$

**/

#include <iostream>
#include <boost/thread.hpp>
#include <boost/bind.hpp>

using namespace boost;

void thread1(int x){
        std::cout << "x= " << x << std::endl;
        for (int i = 0; i < 10; i++){
                std::cout << "thread1: " << i << std::endl;
        }
}
void thread2(int x){
        std::cout << "x= " << x << std::endl;
        for (int i = 0; i < 10; i++){
                std::cout << "thread2: " << i << std::endl;
        }
}

int main(){
        //boost::thread thrd1(&thread1, 2);
        //boost::thread thrd2(&thread2, 3);
        boost::thread thrd1(boost::bind(&thread1, 1));//boost::bind()
        boost::thread thrd2(boost::bind(&thread2, 2));
        thrd1.join(); // main thread wait until thread1 is finished
        thrd2.join();
        return 0;
}

 

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值