Boost libraries

Alright. I am going crazy. I can not get the boost library to work.

I have ubuntu and went to the synaptic package manager and installed libboost1.42. Which is supposed to be supported by Ubuntu.

I try to compile through the terminal and it says undefined reference to boost::thread

The files wont compile.
Any ideas?

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
#include <boost/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;
}
Are you sure that it is not compiling? It should compile, but the linker may not be able to build an executable.

Are you linking with -lboost_thread-mt?

make LDFLAGS=-lboost_thread-mt hello
justin@justin-K61IC:~/Desktop$ make LDFLAGS=-lboost_thread-mt hello
make: *** No rule to make target `hello'. Stop.

You wanted me to put that in terminal right?
Boost.Thread is available as a separate package as it's one of the few non-header-only libraries in boost.
The package is libboost-thread-dev. You can also install libboost-all-dev - that will install all boost packages.
The boost thread files are there in the include folder
They have to built seperately, dont they? Maybe that is what I am missing
They have to built seperately, dont they?

Yes, however you get pre-built binaries when you install libboost-thread-dev.

As for your current problem, you seem to be missing a makefile. Either create one or invoke the compiler directly.
How do i do that?
make: *** No rule to make target `hello'. Stop.

What is the name of your source file? Mine was "hello.cpp", which is why my make target is called "hello". Yours obviously is not. Fix that problem first.
I try to compile through the terminal and it says undefined reference to boost::thread


What command have you been typing?

You will most probably need to add -lboost_thread-mt to it.
So I am new to Linux and c++.

I know how to use g++ to compile the program then run the a.out

But when using make with the -lboost on it. How do i run the compiled file?
Please answer two questions so that we can better help you.

What is the name of your source file?

What are you typing into the command line to build your executable?
Topic archived. No new replies allowed.