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