Problem linking boost::threads using MSVC6 SP4
I've created a windows console project with VC++ 6.0 and just used
one of the examples in the documentation. I've also added the
BOOST_HAS_THREADS macro in the settings. The program compiles well in
debug mode but gives the following linking errors:
Compiling...
main.cpp
Linking...
msvcprtd.lib(MSVCP60D.dll) : error LNK2005: "public: virtual
__thiscall std::runtime_error::~runtime_error(void)" (??
1runtime_error@std@@UAE@XZ) already defined in main.obj
msvcprtd.lib(MSVCP60D.dll) : error LNK2005: "public: __thiscall
std::runtime_error::runtime_error(class runtime_error::runtime_error
const &)" (??0runtime_error@std@@QAE@ABV01@@Z) already defined in
main.obj
msvcprtd.lib(MSVCP60D.dll) : error LNK2005: "public: __thiscall
std::basic_string ::allocator<char> const &)" (??0?$basic_string@DU?
$char_traits@D@std@@V?$allocator@D@2@@std@@QAE@PBDABV?
$allocator@D@1@@Z) already defined in main.obj
LINK : warning LNK4098: defaultlib "MSVCRTD" conflicts with use of
other libs; use /NODEFAULTLIB:library
Debug/threads.exe : fatal error LNK1169: one or more multiply defined
symbols found
Error executing link.exe. Any help on this would be appreciated.
Gunnar Olerud
--- In Boost-Users@y..., "gunnarnl"
I've created a windows console project with VC++ 6.0 and just used one of the examples in the documentation. I've also added the BOOST_HAS_THREADS macro in the settings. The program compiles well in debug mode but gives the following linking errors:
You shouldn't add BOOST_HAS_THREADS. This will be set for you by the config headers if you've linked against the multi-threaded runtime libraries.
Compiling... main.cpp Linking... msvcprtd.lib(MSVCP60D.dll) : error LNK2005: "public: virtual __thiscall std::runtime_error::~runtime_error(void)" (?? 1runtime_error@std@@UAE@XZ) already defined in main.obj msvcprtd.lib(MSVCP60D.dll) : error LNK2005: "public: __thiscall std::runtime_error::runtime_error(class runtime_error::runtime_error const &)" (??0runtime_error@std@@QAE@ABV01@@Z) already defined in main.obj msvcprtd.lib(MSVCP60D.dll) : error LNK2005: "public: __thiscall std::basic_string
::~basic_string (void)" (??1? $basic_strin g@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@QAE@XZ) already defined in main.obj msvcprtd.lib(MSVCP60D.dll) : error LNK2005: "public: __thiscall std::runtime_error::runtime_error(class runtime_error::basic_string const &)" (??0runtime_error@std@@QAE@ABV? $basic_strin g@DU?$char_traits@D@std@@V?$allocator@D@2@@1@@Z) already defined in libcpmtd.lib(ios.obj) msvcprtd.lib(MSVCP60D.dll) : error LNK2005: "public: __thiscall std::basic_string ::basic_string (char const *,class basic_ string ::allocator<char> const &)" (??0?$basic_string@DU? $char_traits@D@std@@V?$allocator@D@2@@std@@QAE@PBDABV? $allocator@D@1@@Z) already defined in main.obj LINK : warning LNK4098: defaultlib "MSVCRTD" conflicts with use of other libs; use /NODEFAULTLIB:library Debug/threads.exe : fatal error LNK1169: one or more multiply defined symbols found Error executing link.exe.
Link errors like this are an indication that both the DLL and the LIB version of the C RTL have been linked into your application. If you are using the last release of Boost Jam built only libraries that link against the DLL version of the C RTL and you should do the same in your application (Project | Settings | C/C++ | Code Generation | Use run-time library | (Debug) Multithreaded DLL). The current CVS Jamfiles will build libraries that link against both the DLL and the LIB version of the C RTL so you'll be able to choose which to link against with your own applications, but you'll need to insure you link against the correct libboost_thread.lib in that case.
Any help on this would be appreciated.
Hope that helped. Bill Kempf
--- In Boost-Users@y..., "gunnarnl"
wrote: I've created a windows console project with VC++ 6.0 and just used one of the examples in the documentation. I've also added the BOOST_HAS_THREADS macro in the settings. The program compiles well in debug mode but gives the following linking errors:
You shouldn't add BOOST_HAS_THREADS. This will be set for you by
config headers if you've linked against the multi-threaded runtime libraries.
Compiling... main.cpp Linking... msvcprtd.lib(MSVCP60D.dll) : error LNK2005: "public: virtual __thiscall std::runtime_error::~runtime_error(void)" (?? 1runtime_error@std@@UAE@XZ) already defined in main.obj msvcprtd.lib(MSVCP60D.dll) : error LNK2005: "public: __thiscall std::runtime_error::runtime_error(class runtime_error::runtime_error const &)" (??0runtime_error@std@@QAE@ABV01@@Z) already defined in main.obj msvcprtd.lib(MSVCP60D.dll) : error LNK2005: "public: __thiscall std::basic_string
::~basic_string (void)" (??1? $basic_strin g@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@QAE@XZ) already defined in main.obj msvcprtd.lib(MSVCP60D.dll) : error LNK2005: "public: __thiscall std::runtime_error::runtime_error(class runtime_error::basic_string const &)" (??0runtime_error@std@@QAE@ABV? $basic_strin g@DU?$char_traits@D@std@@V?$allocator@D@2@@1@@Z) already defined in libcpmtd.lib(ios.obj) msvcprtd.lib(MSVCP60D.dll) : error LNK2005: "public: __thiscall std::basic_string ::basic_string (char const *,class basic_ string ::allocator<char> const &)" (??0?$basic_string@DU? $char_traits@D@std@@V?$allocator@D@2@@std@@QAE@PBDABV? $allocator@D@1@@Z) already defined in main.obj LINK : warning LNK4098: defaultlib "MSVCRTD" conflicts with use of other libs; use /NODEFAULTLIB:library Debug/threads.exe : fatal error LNK1169: one or more multiply defined symbols found Error executing link.exe.
Link errors like this are an indication that both the DLL and the LIB version of the C RTL have been linked into your application. If you are using the last release of Boost Jam built only libraries that link against the DLL version of the C RTL and you should do the same in your application (Project | Settings | C/C++ | Code Generation | Use run-time library | (Debug) Multithreaded DLL). The current CVS Jamfiles will build libraries that link against both the DLL and
Yes, thank you. This helped. I have also removed the
BOOST_HAS_THREADS from my settings and it works fine. However, I have
now of course a question regarding the multithreaded DLL. I normally
compile using the pure multithreaded. What's the difference to the
multithreaded DLL? How do I change the jam files so that I compile
the boost library with the pure multithreaded. I have now only got
the multithreaded DLL versions.
Maybe I should always use the multithreaded DLL as default.
Gunnar Olerud
--- In Boost-Users@y..., "bill_kempf"
LIB version of the C RTL so you'll be able to choose which to link against with your own applications, but you'll need to insure you link against the correct libboost_thread.lib in that case.
Any help on this would be appreciated.
Hope that helped.
Bill Kempf
--- In Boost-Users@y..., "gunnarnl"
Yes, thank you. This helped. I have also removed the BOOST_HAS_THREADS from my settings and it works fine. However, I have now of course a question regarding the multithreaded DLL. I normally compile using the pure multithreaded. What's the difference to the multithreaded DLL? How do I change the jam files so that I compile the boost library with the pure multithreaded. I have now only got the multithreaded DLL versions.
The "pure multithreaded" just links against a static library version of the C RTL, while the "multithreaded DLL" links against the import library for msvcrt.dll. In this case you must be sure that platforms you install your application on have msvcrt.dll installed (it's redistributable so you can install this DLL in your setup). Other then this, there's no noticable difference.
Maybe I should always use the multithreaded DLL as default.
I do :). However, there's legitimate reasons to want to use static linking. It all depends on your deployment needs, mostly. Bill Kempf
participants (2)
-
bill_kempf
-
gunnarnl