Visual C++ 运行时库链接器问题
观察这个接近的场景,即使它看起来与我之前的问题相同。 我仍然没有得到答案。 所以请不要报告为重复项。
我有一个具有 10 个依赖项的项目。 首先,我在主项目的 C/C++ 代码生成部分中使用 /MTD 选项进行编译,并且其所有依赖项均已成功构建。
接下来,我将选项从 /MTD 更改为 /MDd,并且所有依赖项目都得到了 构建成功。 但对于主项目,会报告以下错误:
LIBCMTD.lib(osfinfo.obj) : error LNK2005: __open_osfhandle already defined in MSVCRTD.lib(MSVCR80D.dll)
LIBCMTD.lib(lseeki64.obj) : error LNK2005: __lseeki64 already defined in MSVCRTD.lib(MSVCR80D.dll)
sqlite3x.lib(sqlite3x_command.obj) : error LNK2005: "protected: wchar_t * __thiscall std::basic_string<wchar_t,struct std::char_traits<wchar_t>,class std::allocator<wchar_t> >::_Myptr(void)" (?_Myptr@?$basic_string@_WU?$char_traits@_W@std@@V?$allocator@_W@2@@std@@IAEPA_WXZ) already defined in msvcprtd.lib(MSVCP80D.dll)
MSVCRTD.lib(MSVCR80D.dll) : error LNK2005: __mkdir already defined in LIBCMTD.lib(mkdir.obj)
MSVCRTD.lib(MSVCR80D.dll) : error LNK2005: __strdup already defined in
LIBCMTD.lib(strdup.obj)
Creating library Debug/Application.lib and object Debug/Application.exp
LINK : warning LNK4098: defaultlib 'MSVCRTD' conflicts with use of other libs; use /NODEFAULTLIB:library
LINK : warning LNK4098: defaultlib 'LIBCMTD' conflicts with use of other libs; use /NODEFAULTLIB:library
我该如何解决这个问题?
Observe this close Scenario even though it appears to be the same as my previous questions. Still I am not getting an answer. So please don't report as a duplicate.
I have a project which has 10 dependencies. First I compiled using the /MTD option in the C/C++ codegeneration section in the main project and all its dependencies are getting build successfully.
Next I changed the option from /MTD to /MDd and again all dependent projects are getting
build successfully. But for the main project the following errors are reported:
LIBCMTD.lib(osfinfo.obj) : error LNK2005: __open_osfhandle already defined in MSVCRTD.lib(MSVCR80D.dll)
LIBCMTD.lib(lseeki64.obj) : error LNK2005: __lseeki64 already defined in MSVCRTD.lib(MSVCR80D.dll)
sqlite3x.lib(sqlite3x_command.obj) : error LNK2005: "protected: wchar_t * __thiscall std::basic_string<wchar_t,struct std::char_traits<wchar_t>,class std::allocator<wchar_t> >::_Myptr(void)" (?_Myptr@?$basic_string@_WU?$char_traits@_W@std@@V?$allocator@_W@2@@std@@IAEPA_WXZ) already defined in msvcprtd.lib(MSVCP80D.dll)
MSVCRTD.lib(MSVCR80D.dll) : error LNK2005: __mkdir already defined in LIBCMTD.lib(mkdir.obj)
MSVCRTD.lib(MSVCR80D.dll) : error LNK2005: __strdup already defined in
LIBCMTD.lib(strdup.obj)
Creating library Debug/Application.lib and object Debug/Application.exp
LINK : warning LNK4098: defaultlib 'MSVCRTD' conflicts with use of other libs; use /NODEFAULTLIB:library
LINK : warning LNK4098: defaultlib 'LIBCMTD' conflicts with use of other libs; use /NODEFAULTLIB:library
How can I fix this?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您不能混合使用 C 运行时库。 如果您有一个编译为 /MT(任何东西)的库或对象,则不能仅与 /MD 链接。 您需要与线程安全的 MSVCRT 链接。 没有“如果”、“但是”。 您不能混合使用C 运行时。 我总是发现,即使在不执行线程的程序中,最好只使用 /MT。
您是否运行了项目清理操作来删除已构建的对象和库? 您在这里也依赖于 SQLite,您是否也重建了它?
You cannot mix C runtime libraries. If you have a library or object compiled /MT(anything), you cannot just link with /MD. You need to link with the threadsafe MSVCRT. There's no if's and's or but's about it. You CANNOT mix C runtimes. I've always found it best, even in programs that don't do threading, to just use /MT.
Did you run a project clean operation to remove already built objects and libraries? You have a dependency on SQLite here as well, did you rebuild that, too?
当一堆静态 C++ 库链接在一起时,它们都必须具有 /MTD 或者它们都必须具有 /MDd。您不能将具有 /MTD 的项目与具有 /MDd 的另一个项目链接
这可能是您链接的原因错误。 您仅在主项目上获得它的原因是您的主项目是唯一实际执行链接的项目。请告诉我们它是否解决了您的问题。
我记得我曾经在 /MTD 和 /MDd 上遇到过同样的问题,并且我有非常相似的错误。
When a bunch of static c++ library are linked all together , they all must have /MTD or they all must have /MDd.You can't link a project with /MTD with another project with /MDd
This is probably the reason for your linking errors. The reason why you are getting it only on your main project is that your main project is the only one that actually do the linking.Please tell us if it resolved your problem.
I recall I once had the same problem with /MTD and /MDd and I had very similar errors.
我的回答此处可能会有所帮助,链接到一些我发现对于解决我的这个问题版本非常有用的 MSDN 文章。
My answer here might be of some help, linking to some MSDN articles I found very useful in solving my version of this problem.