Boost logo

Boost Users :

From: Ben Hutchings (ben.hutchings_at_[hidden])
Date: 2004-05-25 06:07:32


Mike Feldmeier <pooky_bunny_at_[hidden]> wrote:
> I've seen variations of this come up in this newsgroup and elsewhere,
> but I have yet to find an answer that works for me.
>
> class threaded_manager
> {
> public:
> void start(void);
> };
>
> threaded_manager mgr;
>
> boost::thread(boost::bind(&threaded_manager::start, &mgr));
>
> This consistently produces the linking error:
>
> converter.obj : error LNK2019: unresolved external symbol
> "__declspec(dllimport) public: __thiscall boost::thread::thread(class
> boost::function0<void,class
> _STL::allocator<class boost::function_base> > const &)"
> (__imp_??0thread_at_boost@@QAE_at_ABV?$function0_at_XV?$allocator_at_Vfunction_bas
> e_at_boost@@@_STL@@@1@@Z) referenced in function "public: void __thiscall
> mytest::test::converter::run(void)"
> (?run_at_converter@test_at_mytest@@QAEXXZ)

I think you aren't linking with the thread library. Many of the Boost
libraries (such as Boost.Bind) include their implementation entirely in
header files, so they will be compiled into your program as needed.
Boost.Thread doesn't; you need to build it as a library (and on Windows
it must be a DLL) and link it with your program.

> Separating the two boost functions on to separate lines works fine:
>
> boost::bind(&threaded_manager::start, &mgr);
> boost::thread();
>
> ..which indicates to me that bind is returning an object that is not
> compatible with thread, but I've seen multiple examples of just this
> type of call.
<snip>

If that were the case you should see a compiler error. The two lines
above may work because the default constructor for boost::thread is
compiled inline whereas the other constructor must be linked in.
Having said that, though, neither v1.30 nor v1.31 has the default
constructor definition in the header, so I don't entirely understand
what's going on. Did you perhaps mistakenly declare a function
returning a boost::thread?

Ben.


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