c++ - 尝试链接 boost::filesystem 以调试 MSVC11 项目时出现链接器错误

标签 c++ visual-c++ boost linker

我试图在我的项目中使用 boost::filesystem,但我遇到了链接器错误:

Error   14  error LNK1169: one or more multiply defined symbols found   C:\Users\Developer\Desktop\mandala3d\Debug\mandala.exe  1   1   mandala
Error   5   error LNK2005: "public: __thiscall std::bad_cast::bad_cast(char const *)" (??0bad_cast@std@@QAE@PBD@Z) already defined in MSVCRTD.lib(MSVCR110D.dll)    C:\Users\Developer\Desktop\mandala3d\mandala\LIBCMT.lib(stdexcpt.obj)   mandala
Error   4   error LNK2005: "public: __thiscall std::bad_cast::bad_cast(class std::bad_cast const &)" (??0bad_cast@std@@QAE@ABV01@@Z) already defined in MSVCRTD.lib(MSVCR110D.dll)  C:\Users\Developer\Desktop\mandala3d\mandala\LIBCMT.lib(stdexcpt.obj)   mandala
Error   12  error LNK2005: "public: __thiscall std::exception::exception(char const * const &)" (??0exception@std@@QAE@ABQBD@Z) already defined in LIBCMT.lib(stdexcpt.obj) C:\Users\Developer\Desktop\mandala3d\mandala\MSVCRTD.lib(MSVCR110D.dll) mandala
Error   6   error LNK2005: "public: __thiscall std::exception::exception(class std::exception const &)" (??0exception@std@@QAE@ABV01@@Z) already defined in MSVCRTD.lib(MSVCR110D.dll)  C:\Users\Developer\Desktop\mandala3d\mandala\LIBCMT.lib(stdexcpt.obj)   mandala
Error   7   error LNK2005: "public: __thiscall std::exception::exception(void)" (??0exception@std@@QAE@XZ) already defined in MSVCRTD.lib(MSVCR110D.dll)    C:\Users\Developer\Desktop\mandala3d\mandala\LIBCMT.lib(stdexcpt.obj)   mandala
Error   8   error LNK2005: "public: virtual __thiscall std::bad_cast::~bad_cast(void)" (??1bad_cast@std@@UAE@XZ) already defined in MSVCRTD.lib(MSVCR110D.dll)  C:\Users\Developer\Desktop\mandala3d\mandala\LIBCMT.lib(stdexcpt.obj)   mandala
Error   9   error LNK2005: "public: virtual __thiscall std::exception::~exception(void)" (??1exception@std@@UAE@XZ) already defined in MSVCRTD.lib(MSVCR110D.dll)   C:\Users\Developer\Desktop\mandala3d\mandala\LIBCMT.lib(stdexcpt.obj)   mandala
Error   13  error LNK2005: "public: virtual char const * __thiscall std::exception::what(void)const " (?what@exception@std@@UBEPBDXZ) already defined in LIBCMT.lib(stdexcpt.obj)   C:\Users\Developer\Desktop\mandala3d\mandala\MSVCRTD.lib(MSVCR110D.dll) mandala
Error   10  error LNK2005: __invalid_parameter already defined in MSVCRTD.lib(MSVCR110D.dll)    C:\Users\Developer\Desktop\mandala3d\mandala\LIBCMT.lib(invarg.obj) mandala
Error   11  error LNK2005: __invoke_watson already defined in MSVCRTD.lib(MSVCR110D.dll)    C:\Users\Developer\Desktop\mandala3d\mandala\LIBCMT.lib(invarg.obj) mandala

我正在使用以下命令构建 boost:

bootstrap
.\b2

我指向库包含目录的 $BOOSTDIR\stage\lib,我的编译器是 Visual Studio 2012 (v110)

我曾尝试直接链接在 $BOOSTDIR\lib\* 目录中生成的 debug 库,但遇到了其他错误。我还怀疑这不是静态链接库的标准或预期方式。

我在这里做错了什么?

最佳答案

您正在混合使用 C 运行时库链接和调试/发布二进制文件。

libcmt是静态C运行库的发布版本,而msvcrtd是动态C运行库的调试版本。你在错误中同时出现了这两种情况,这意味着你试图将它们混合在一起,但你做不到。

您需要重建 Boost 以使用与您的项目相同版本的 C 运行时,或者重建您的项目以使用与 Boost 相同的版本。但是,您目前混合使用调试和发布库的事实通常表明您的设置确实存在其他问题。

如果您查看项目的属性并转到 C/C++ -> 代码生成,您将看到“运行时库”字段。您可以更改它以指定您的项目应如何链接到 C 运行时。/MDd 将链接 msvcrtd.dll,而/MT 将链接 libcmt.lib

关于c++ - 尝试链接 boost::filesystem 以调试 MSVC11 项目时出现链接器错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19415544/

相关文章:

c++ - 错误 "fatal error C1034: windows.h: no include path set"

c++ - 如何拥有具有不同类型值的 map ?

c++ - C++中退出进程的不同方式

c++ - 使用 Boost::units 在两个数量之间进行转换的最简单方法?

c++ - 访问给定的 future 后 boost::future<>.then() 中的错误访问

c++ - 为什么锁会起作用?

c++ - 有没有像 "#pragma ignore this sourcefile"这样的 MSVC 编译器?

c++ - 在头文件中初始化可自定义结构的 vector

c++ - 错误: “expression must have class type” & “left of must have class/struct/union”

c++ - CPP + 正则表达式来验证 URL