Opened 15 years ago
Closed 14 years ago
#1053 closed Support Requests (invalid)
Error using boost::mutex and C++/CLI
Reported by: | Owned by: | Anthony Williams | |
---|---|---|---|
Milestone: | To Be Determined | Component: | thread |
Version: | Boost 1.34.0 | Severity: | Showstopper |
Keywords: | c++/cli mutex clr | Cc: |
Description
Hello,
I have the following code:
---- first.h
#ifndef _first_h_included_ #define _first_h_included_
#include <boost/thread/mutex.hpp> #include <iostream> #include <string>
namespace test_first {
static boost::mutex io_mutex;
struct console {
public:
static void write(std::string s);
};
}
#endif
---- END first.h
---- first.cpp
#include "first.h"
namespace test_first {
void console::write(std::string s) {
{
boost::mutex::scoped_lock sl(io_mutex); std::cout << s;
}
}
}
---- END first.cpp
I compile this code using Visual Studio 2005 as a LIB file. I compile withOUT /CLR option.
The problem is in the next file, "executable.cpp".
---- executable.cpp #include <string> #include "first.h"
int main (int argc, char *argv[]) {
test_first::console::write("fer");
std::cin.get(); return 0;
} ---- END executable.cpp
When I try to use this LIB in a C++/CLI source file, compiled with /CLR option, I have the followings errors:
Error 1 error LNK2005: "public: void thiscall std::_Mutex::_Lock(void)" (?_Lock@_Mutex@std@@QAEXXZ) already defined in msvcprt.lib(MSVCP80.dll) libcpmt.lib
Error 2 error LNK2005: "public: void thiscall std::_Mutex::_Unlock(void)" (?_Unlock@_Mutex@std@@QAEXXZ) already defined in msvcprt.lib(MSVCP80.dll) libcpmt.lib
Error 3 fatal error LNK1104: cannot open file 'libboost_thread-vc80-mt-s-1_34.lib' Executable
The boost::mutex LIB file that I use is: "libboost_thread-vc80-mt-1_34.lib".
Thanks to all. Fernando Pelliccioni. Buenos Aires, Argentina.
Attachments (1)
Change History (4)
by , 15 years ago
Attachment: | TwoLibrariesTest_rar added |
---|
comment:1 by , 15 years ago
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).
See http://msdn2.microsoft.com/en-us/library/abx4dbyh(VS.80).aspx
You cannot use the statically linked CRT ( /MT or /MTd options) with /clr. Use the dynamically-linked libraries (/MD or /MDd) instead.
comment:2 by , 15 years ago
Sorry for the delay.
The problem is solved.
Thank you very much.
Fernando Pelliccioni. Buenos Aires, Argentina.
comment:3 by , 14 years ago
Resolution: | → invalid |
---|---|
Status: | new → closed |
Complete Source Code