RE: [Boost-users] boost::thread, boost::bind, and member functions
From: "Ben Hutchings"
Reply-To: boost-users@lists.boost.org To: Subject: RE: [Boost-users] boost::thread, boost::bind, and member functions Date: Tue, 25 May 2004 12:07:32 +0100 Mike Feldmeier
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
const &)" (__imp_??0thread@boost@@QAE@ABV?$function0@XV?$allocator@Vfunction_bas e@boost@@@_STL@@@1@@Z) referenced in function "public: void __thiscall mytest::test::converter::run(void)" (?run@converter@test@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.
I'm using Visual C++ 7.1, but using straight C++, no .NET. I've defined the addtional library path (C:\boost\lib) and tried linking (in the additional dependencies) with boost_thread-vc71-mt-gdp-1_31.lib, boost_thread-vc71-mt-gdp.lib, boost_thread-vc71-mt-p-1_31.lib, and boost_thread-vc71-mt-p.lib (one at a time, of course), but I get the same error message with all of them.
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?
Thus far, this line (or two lines) are the only boost-related lines in my code.
Ben.
_______________________________________________ Boost-users mailing list Boost-users@lists.boost.org http://lists.boost.org/mailman/listinfo.cgi/boost-users
Thanks, Mike _________________________________________________________________ Get 200+ ad-free, high-fidelity stations and LIVE Major League Baseball Gameday Audio! http://radio.msn.click-url.com/go/onm00200491ave/direct/01/
participants (1)
-
Mike Feldmeier