Boost logo

Boost Users :

Subject: [Boost-users] [boost-users] Compile and Install boost::thread from souce code on Ubuntu
From: Boost lzw (boostlzw_at_[hidden])
Date: 2010-06-17 09:24:53


Hi, there,

The most updated version of boost on my Ubuntu is 1_40_0. So I choose
to compile and install 1_43_0 from source code. During the building process
of step 4 (mentioned bellow), I was prompted that boost::thread, boost::mpi,
etc. libraries need to be compiled and installed separetly. I ignored them
and finished the process.

Now I can run the following program sucessfully with
// robert_at_ubuntu:~/boost$ g++ -I /home/robert/src/boost_1_43_0 example.cpp
-o example
// echo 1 2 3 | ./example

for example.cpp
===================
#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) << " " );
}
 ===================

but failed to compile thread.cpp program with
robert_at_ubuntu:~/boost$ g++ -I /home/robert/src/boost_1_43_0 thread.cpp -o
thread

for the following thread.cpp
 ===================
#include <boost/thread/thread.hpp>
#include <iostream>
void hello()
{
    std::cout << "Hello world, I'm a thread!" << std::endl;
}
int main(int argc, char* argv[])
{
    boost::thread thrd(&hello);
    thrd.join();
    return 0;
}
 ===================

The first few complaints I got are:
----------------------------------------------
/tmp/ccwgSZ3d.o: In function `main':
thread.cpp:(.text+0x6e): undefined reference to `boost::thread::join()'
thread.cpp:(.text+0x7f): undefined reference to `boost::thread::~thread()'
thread.cpp:(.text+0xa0): undefined reference to `boost::thread::~thread()'
/tmp/ccwgSZ3d.o: In function
`boost::detail::thread_data_base::thread_data_base()':
How can I compile boost::thread separately for it to work? Thanks a lot.

By the way, these are steps I did to compile and install boost_1_43_0 in
case that you may want to review it (or I did something wrong):
[NOTE: The downloaded boost_1_43_0 source code located at my home directory:
~/src/ ]
(0)
cd ~/src

(1)
wget
http://sourceforge.net/projects/boost/files/boost/1.43.0/boost_1_43_0.tar.gz/download

(2)
tar zxvf boost_1_43_0.tar.gz

(3)
cd boost_1_43_0

(4)
robert_at_ubuntu:~/src/boost_1_43_0$ sudo ./bootstrap.sh --prefix=/usr/local
--show-libraries --with-libraries=all --exec-prefix=/usr/local/bin/

(5)
./bjam install



Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net