Boost C++ Libraries: Ticket #1053: Error using boost::mutex and C++/CLI https://svn.boost.org/trac10/ticket/1053 <p> Hello, </p> <p> I have the following code: </p> <p> <em>---- first.h </em></p> <p> #ifndef _first_h_included_ #define _first_h_included_ </p> <p> #include &lt;boost/thread/mutex.hpp&gt; #include &lt;iostream&gt; #include &lt;string&gt; </p> <p> namespace test_first { </p> <blockquote> <p> static boost::mutex io_mutex; </p> </blockquote> <blockquote> <p> struct console { </p> </blockquote> <blockquote> <p> public: </p> </blockquote> <blockquote> <blockquote> <p> static void write(std::string s); </p> </blockquote> </blockquote> <blockquote> <p> }; </p> </blockquote> <p> } </p> <p> #endif </p> <p> <em>---- END first.h </em></p> <p> <em>---- first.cpp </em></p> <p> #include "first.h" </p> <p> namespace test_first { </p> <blockquote> <p> void console::write(std::string s) { </p> <blockquote> <p> { </p> <blockquote> <p> boost::mutex::scoped_lock sl(io_mutex); std::cout &lt;&lt; s; </p> </blockquote> <p> } </p> </blockquote> <p> } </p> </blockquote> <p> } </p> <p> <em>---- END first.cpp </em></p> <p> I compile this code using Visual Studio 2005 as a LIB file. I compile withOUT /CLR option. </p> <p> The problem is in the next file, "executable.cpp". </p> <p> <em>---- executable.cpp #include &lt;string&gt; #include "first.h" </em></p> <p> int main (int argc, char *argv[]) { </p> <blockquote> <p> test_first::console::write("fer"); </p> </blockquote> <blockquote> <p> std::cin.get(); return 0; </p> </blockquote> <p> } <em>---- END executable.cpp </em></p> <p> When I try to use this LIB in a C++/CLI source file, compiled with /CLR option, I have the followings errors: </p> <p> Error 1 error LNK2005: "public: void <span class="underline">thiscall std::_Mutex::_Lock(void)" (?_Lock@_Mutex@std@@QAEXXZ) already defined in msvcprt.lib(MSVCP80.dll) libcpmt.lib </span></p> <p> Error 2 error LNK2005: "public: void <span class="underline">thiscall std::_Mutex::_Unlock(void)" (?_Unlock@_Mutex@std@@QAEXXZ) already defined in msvcprt.lib(MSVCP80.dll) libcpmt.lib </span></p> <p> Error 3 fatal error LNK1104: cannot open file 'libboost_thread-vc80-mt-s-1_34.lib' Executable </p> <p> The boost::mutex LIB file that I use is: "libboost_thread-vc80-mt-1_34.lib". </p> <p> Thanks to all. Fernando Pelliccioni. Buenos Aires, Argentina. </p> en-us Boost C++ Libraries /htdocs/site/boost.png https://svn.boost.org/trac10/ticket/1053 Trac 1.4.3 fpelliccioni@… Fri, 15 Jun 2007 15:28:24 GMT attachment set https://svn.boost.org/trac10/ticket/1053 https://svn.boost.org/trac10/ticket/1053 <ul> <li><strong>attachment</strong> → <span class="trac-field-new">TwoLibrariesTest_rar</span> </li> </ul> <p> Complete Source Code </p> Ticket volc@… Mon, 25 Jun 2007 23:47:29 GMT <link>https://svn.boost.org/trac10/ticket/1053#comment:1 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/1053#comment:1</guid> <description> <p> Not really sure if that's the problem but using the static versions of the C Run-Time Library (LIBCPMT.LIB, LIBCPMTD.LIB) not possible when compiling mixed/managed code (e.g. C++/CLI with /CLR). </p> <p> See <a class="ext-link" href="http://msdn2.microsoft.com/en-us/library/abx4dbyh(VS.80).aspx"><span class="icon">​</span>http://msdn2.microsoft.com/en-us/library/abx4dbyh(VS.80).aspx</a> </p> <p> You cannot use the statically linked CRT ( /MT or /MTd options) with /clr. Use the dynamically-linked libraries (/MD or /MDd) instead. </p> </description> <category>Ticket</category> </item> <item> <author>fpelliccioni@…</author> <pubDate>Fri, 04 Apr 2008 17:37:46 GMT</pubDate> <title/> <link>https://svn.boost.org/trac10/ticket/1053#comment:2 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/1053#comment:2</guid> <description> <p> Sorry for the delay. </p> <p> The problem is solved. </p> <p> Thank you very much. </p> <p> Fernando Pelliccioni. Buenos Aires, Argentina. </p> </description> <category>Ticket</category> </item> <item> <dc:creator>Anthony Williams</dc:creator> <pubDate>Mon, 28 Apr 2008 09:29:27 GMT</pubDate> <title>status changed; resolution set https://svn.boost.org/trac10/ticket/1053#comment:3 https://svn.boost.org/trac10/ticket/1053#comment:3 <ul> <li><strong>status</strong> <span class="trac-field-old">new</span> → <span class="trac-field-new">closed</span> </li> <li><strong>resolution</strong> → <span class="trac-field-new">invalid</span> </li> </ul> Ticket