VC++ boost.Thread library usage ?

Hi, I am getting the following error. I see that it is trying to link to the static library, but I still get this error. Would appreciate if someone can correct my usage. Linking to lib file: lib"boost_thread"-vc71-mt-sgd-1_31.lib c:\Boost\include\boost-1_31\boost\config\auto_link.hpp(269) : fatal error C1189: #error : "Mixing a dll boost library with a static runtime is a really bad idea..." Here is my sample: #define _MSC_VER 1310 #define BOOST_LIB_NAME "boost_thread" #define BOOST_LIB_DIAGNOSTIC "on"// Show library file details. #include <boost/config/auto_link.hpp> #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; }

I posted the following answer to your original question yesterday: http://article.gmane.org/gmane.comp.lib.boost.devel/34895 There must be something wrong with your news feed if you haven't received that message. Regards, Andreas

Boost.thread is currently only available as a dll that links to the dynamic runtime, to use it you will either have to: 1) do the same thing, and link to the dll runtime. or 2) build your own cut down version of the lib (if you search the list you should find other people who have managed to do the same, basically I think it means leaving out the thread-specific-ptr code), then define BOOST_THREAD_NO_LIB (to disable auto-linking) and link to your custom build of the thread lib. John.

Hi, I'm currently starting to give a try to boost.thread lib. I've been successfully compiling boost.thread library (from boost 1.31.0) as a DLL with VC71, and I also compile the alarm example which seems to work fine, although I get a few warnings during the compilation (listed below). Do these warnings have been fixed since 1.31.0 ? Would they prevent any "real" app from working ? Thanks in advance, Nicolas ---- Note: including file: d:\Projets\Muybridge\src2\muybridge\boost\boost/version.hpp d:\Projets\Muybridge\src2\muybridge\boost\boost\thread\exceptions.hpp(29) : warning C4275: non dll-interface class 'std::logic_error' used as base for dll-interface class 'boost::lock_error' c:\Program Files\Microsoft Visual Studio .NET 2003\Vc7\include\stdexcept(14) : see declaration of 'std::logic_error' d:\Projets\Muybridge\src2\muybridge\boost\boost\thread\exceptions.hpp(28) : see declaration of 'boost::lock_error' d:\Projets\Muybridge\src2\muybridge\boost\boost\thread\exceptions.hpp(35) : warning C4275: non dll-interface class 'std::runtime_error' used as base for dll-interface class 'boost::thread_resource_error' c:\Program Files\Microsoft Visual Studio .NET 2003\Vc7\include\stdexcept(136) : see declaration of 'std::runtime_error' d:\Projets\Muybridge\src2\muybridge\boost\boost\thread\exceptions.hpp(34) : see declaration of 'boost::thread_resource_error' Note: including file: d:\Projets\Muybridge\src2\muybridge\boost\boost/thread/detail/config.hpp d:\Projets\Muybridge\src2\muybridge\boost\boost\thread\mutex.hpp(36) : warning C4275: non dll-interface class 'boost::noncopyable' used as base for dll-interface class 'boost::mutex' d:\Projets\Muybridge\src2\muybridge\boost\boost\noncopyable.hpp(22) : see declaration of 'boost::noncopyable' d:\Projets\Muybridge\src2\muybridge\boost\boost\thread\mutex.hpp(35) : see declaration of 'boost::mutex' d:\Projets\Muybridge\src2\muybridge\boost\boost\thread\mutex.hpp(74) : warning C4275: non dll-interface class 'boost::noncopyable' used as base for dll-interface class 'boost::try_mutex' d:\Projets\Muybridge\src2\muybridge\boost\boost\noncopyable.hpp(22) : see declaration of 'boost::noncopyable' d:\Projets\Muybridge\src2\muybridge\boost\boost\thread\mutex.hpp(73) : see declaration of 'boost::try_mutex' d:\Projets\Muybridge\src2\muybridge\boost\boost\thread\mutex.hpp(114) : warning C4275: non dll-interface class 'boost::noncopyable' used as base for dll-interface class 'boost::timed_mutex' d:\Projets\Muybridge\src2\muybridge\boost\boost\noncopyable.hpp(22) : see declaration of 'boost::noncopyable' d:\Projets\Muybridge\src2\muybridge\boost\boost\thread\mutex.hpp(113) : see declaration of 'boost::timed_mutex' Note: including file: d:\Projets\Muybridge\src2\muybridge\boost\boost/thread/detail/config.hpp Note: including file: C:\Program Files\Microsoft Visual Studio .NET 2003\Vc7\include\list Note: including file: C:\Program Files\Microsoft Visual Studio .NET 2003\Vc7\include\functional d:\Projets\Muybridge\src2\muybridge\boost\boost\thread\thread.hpp(38) : warning C4275: non dll-interface class 'boost::noncopyable' used as base for dll-interface class 'boost::thread' d:\Projets\Muybridge\src2\muybridge\boost\boost\noncopyable.hpp(22) : see declaration of 'boost::noncopyable' d:\Projets\Muybridge\src2\muybridge\boost\boost\thread\thread.hpp(37) : see declaration of 'boost::thread' d:\Projets\Muybridge\src2\muybridge\boost\boost\thread\thread.hpp(67) : warning C4275: non dll-interface class 'boost::noncopyable' used as base for dll-interface class 'boost::thread_group' d:\Projets\Muybridge\src2\muybridge\boost\boost\noncopyable.hpp(22) : see declaration of 'boost::noncopyable' d:\Projets\Muybridge\src2\muybridge\boost\boost\thread\thread.hpp(66) : see declaration of 'boost::thread_group' d:\Projets\Muybridge\src2\muybridge\boost\boost\thread\thread.hpp(78) : warning C4251: 'boost::thread_group::m_threads' : class 'std::list<_Ty>' needs to have dll-interface to be used by clients of class 'boost::thread_group' with [ _Ty=boost::thread * ] ---

Hi, Nicolas LELONG / mgdesign wrote:
As far as I know, they are not something you should be nervous about. Some time ago I found (I do not remember where) a list of warnings that are not helpful at all but can be generated when compiling modern libs. The list of these warnings and the macros I use to shut them up (all this is in the header file that I include where needed) are: // these are the meaningless warnings: // 4097 4127 4250 4251 4275 4284 4290 4291 4355 4505 4511 4512 4514 4554 4706 4710 4786 4800 // for VC++6: _MSC_VER == 1200 # if defined _MSC_VER # if (_MSC_VER == 1200) # pragma warning (disable : 4097 4251 4275 4284 4355 4511 4512 4514 4786) # endif # endif // for VC++7.1: _MSC_VER == 1310 # if defined _MSC_VER # if (_MSC_VER >= 1300) # pragma warning (disable : 4251) # endif # endif I disable only those warnings that were appearing in my compilations (so, as you can see, VC++7.1 generates far less warnings than VC++6) and *only* those from the list above. You may need to modify the disable lists. At least I can show the "0 warnings" message to my boss. ;-) -- Maciej Sobczak : http://www.msobczak.com/ Programming : http://www.msobczak.com/prog/

Maciej, Thanks for your answer,
Some time ago I found (I do not remember where) a list of warnings that are not helpful at all but can be generated when compiling modern libs.
indeed I found a boost document that explicits the warnings to disable (intended for library authors) : <document_quote> #ifdef BOOST_MSVC # pragma warning(push) # pragma warning(disable : 4251 4231 4660) #endif // code here #ifdef BOOST_MSVC #pragma warning(pop) #endif This is safe provided that there are no dependencies that are (template) classes with non-constant static data members, these really do need exporting, otherwise there will be multiple copies of the static data members in the program, and that's really really bad. </document_quote> The whole document is here : http://www.boost.org/more/separate_compilation.html I think I'll have to check soon if the boost.thread classes really don't cause problems, and perhaps propose a patch Thanks, Nicolas

Award yourself a 'bonus point' :-) This shows how desirable it is from a documentation point of view for Boost libraries to try to get to an warning free compilation, at the strictest level if possible. New (and wise) users are rightly concerned about getting warnings - and they cause a lot of clutter on the build log. It has been rightly observed that it is not possible to make a global judgement on whether warnings are helpful or not, but the Boost authors should do so. The way you suggest is fine IMHO. You might like to add a brief description of what the warning is, and perhaps why it can be ignored. This may be a benefit to users of other compilers. # pragma warning(disable: 4511) // Copy constructor could not be generated. # pragma warning(disable: 4512) // Assignment operator could not be generated. It may be better to use BOOST_MSVC rather than _MSC_VER - BUT it must follow some Boost included file that will ensure BOOST_MSVC is defined - a pit into which I have stumbled :-( Paul Paul A Bristow Prizet Farmhouse, Kendal, Cumbria UK LA8 8AB +44 1539 561830 +44 7714 330204 mailto: pbristow@hetp.u-net.com | -----Original Message----- | From: boost-bounces@lists.boost.org | [mailto:boost-bounces@lists.boost.org] On Behalf Of Maciej Sobczak | Sent: 18 March 2004 12:17 | To: boost@lists.boost.org | Subject: Re: [boost] VC71 boost.thread 1.31.0 warnings ?! | | | Hi, | | Nicolas LELONG / mgdesign wrote: | | > I've been successfully compiling boost.thread library (from | boost 1.31.0) as | > a DLL with VC71, and I also compile the alarm example which | seems to work | > fine, although I get a few warnings during the compilation | (listed below). | > | > Do these warnings have been fixed since 1.31.0 ? Would they | prevent any | > "real" app from working ? | | As far as I know, they are not something you should be nervous about. | | Some time ago I found (I do not remember where) a list of | warnings that | are not helpful at all but can be generated when compiling | modern libs. | The list of these warnings and the macros I use to shut them up (all | this is in the header file that I include where needed) are: | | // these are the meaningless warnings: | // 4097 4127 4250 4251 4275 4284 4290 4291 4355 4505 4511 | 4512 4514 4554 | 4706 4710 4786 4800 | | // for VC++6: _MSC_VER == 1200 | | # if defined _MSC_VER | # if (_MSC_VER == 1200) | # pragma warning (disable : 4097 4251 4275 4284 4355 4511 | 4512 4514 | 4786) | # endif | # endif | | // for VC++7.1: _MSC_VER == 1310 | | # if defined _MSC_VER | # if (_MSC_VER >= 1300) | # pragma warning (disable : 4251) | # endif | # endif | | | I disable only those warnings that were appearing in my compilations | (so, as you can see, VC++7.1 generates far less warnings than | VC++6) and | *only* those from the list above. You may need to modify the | disable lists. | | | At least I can show the "0 warnings" message to my boss. ;-) | | -- | Maciej Sobczak : http://www.msobczak.com/ | Programming : http://www.msobczak.com/prog/ | | _______________________________________________ | Unsubscribe & other changes: | http://lists.boost.org/mailman/listinfo.cg| i/boost | |
participants (6)
-
Andreas Huber
-
John Maddock
-
Maciej Sobczak
-
Nicolas LELONG / mgdesign
-
Paul A Bristow
-
raja