下载完整的bjam使用例子:http://download.csdn.net/detail/dotphoenix/9626088
目录结构:
bjam_example
----Jamroot
----src
----Jamfile
---- main.cpp
----lib_src
----hello.cpp
---- weather.cpp
----Jamfile
----inc
----lib.h
Jamroot的内容:
project : requirements <include>"./inc" ;
build-project src ;
src/Jamfile的内容:
<span style="font-family:SimSun;font-size:18px;">exe main : main.cpp boost_thread boost_system ../lib_src//functions ; # 冒號和分號都要記得留空白唷
lib boost_thread : : <name>boost_thread <search>"../../../lib" ;
lib boost_system : : <name>boost_system <search>"../../../lib" ;</span>
src/main.cpp的内容:
<span style="font-family:SimSun;font-size:18px;">#include "lib.h"
int main(int argc, char* argv[])
{
start_hello();
start_weather();
wait_hello();
wait_weather();
return 0;
}
</span>
inc/lib.h的内容:
<span style="font-family:SimSun;font-size:18px;">void start_hello();
void wait_hello();
void start_weather();
void wait_weather();
</span>
lib_src/Jamfile的内容:
<span style="font-family:SimSun;font-size:18px;">lib functions : hello.cpp weather.cpp : <link>static : : <include>"../../../include" ; # 冒號和分號都要記得留空白唷</span>
lib_src/hello.cpp的内容:
<span style="font-family:SimSun;font-size:18px;">#include <iostream>
#include <boost/thread.hpp>
static void fun()
{
int i = 0;
while(i++ < 8)
{
std::cout<<"Hello world!"<< std::endl;
boost::this_thread::sleep(boost::posix_time::seconds(1));
}
}
static boost::thread* thrd;
void start_hello()
{
thrd = new boost::thread(&fun);
}
void wait_hello()
{
thrd->join();
delete thrd;
}</span>
lib_src/weather.cpp的内容:
<span style="font-family:SimSun;font-size:18px;">#include <iostream>
#include <boost/thread.hpp>
static void fun()
{
int i = 0;
while(i++ < 8)
{
std::cout<<"The weather is sunny!"<< std::endl;
boost::this_thread::sleep(boost::posix_time::seconds(1));
}
}
static boost::thread* thrd;
void start_weather()
{
thrd = new boost::thread(&fun);
}
void wait_weather()
{
thrd->join();
delete thrd;
}</span>
然后执行:
../../boost_1_54_0/bjam
PS:
以Jamroot为根目录
bjam所在的位置为../../boost_1_54_0/
boost libraries所在的位置为../../lib
boost headers所在的位置为../../include
需要在.bashrc里面设置如下路径:
BOOST_BUILD_TOOLS_PATH=/home/azhu/sourcecode/boost/boost_1_54_0/tools/build/v2/
export BOOST_BUILD_TOOLS_PATH