Cross-platform thread library using boost

Source: Internet
Author: User

click Download on the homepage to download the SourceForge page. The latest version is boost_000033_1. There are multiple
file formats available for download (package .exe,
.tar.gz, etc.) with the same content, all of which are boost_000033_1 Source Code . Download and decompress the package. (assume the directory is/home/yjguo
/boost_000033_1 ).
most of the content in boost can be directly used by the source Code , while thread needs to compile the corresponding Library first.
Linux:
redhat9.0 is installed by default.
1. compile jam (jam is the basis for compiling other libraries)
enter the/home/yjguo/boost_1_33_1/tools/build/jam_src directory
Run. /build. SH:
after running, the bin is displayed. linuxx86 directory, the bjam we need is under this directory.
the build. Sh script automatically detects GCC and calls GCC to compile bjam. (A lot of information is mentioned in the index.html file under the jam_srcdirectory)


2. compile the thread library
go to the/home/yjguo/boost_000033_1 directory.
run the program. /tools/build/jam_src/bin. linuxx86/bjam -- With-thread stage (only compile thread Library)
after compilation, the result is in the/home/yjguo/boost_1_33_1/bin/Boost/libs/thread/build directory (including debug
/relase,
. a /. in addition, because we use the stage option during compilation, therefore, all the results will be copied to the/home/yjguo/boost_1_33_1
/stage/lib directory.
3. Prepare to use the thread library
select the compiled thread dynamic library (. So share object ).
copy the libboost_thread-gcc-mt-1_33_1.so.1.33.1 to the/usr/lib/directory
copy the libboost_thread-gcc-mt-d-1_33_1.so.1.33.1 to the/usr/lib/directory
to/usr//lib directory run
ln-s libboost_thread-gcc-mt-1_33_1.so.1.33.1 libboost_thread-gcc-mt-1_33_1.so

Ln-s libboost_thread-gcc-mt-d-1_33_1.so.1.33.1 libboost_thread-gcc-mt-d-1_33_1.so
 
4. Use the thread Library

Create the main. cpp file in the/home/yjguo directory with the following content:
# Include <boost/thread. HPP>
# Include <iostream>
Void Hello ()
{
STD: cout <"Hello world, I'm a thread! "<STD: Endl;
}
Main ()
{
Boost: thread thrd (& Hello );
Thrd. Join ();
}
 
Run g ++-I/home/yjguo/boost_1_33_1-pthread-lboost_thread-gcc-mt-1_33_1 main. cpp to get the. Out file.

./A. Out to run.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

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.