Visual C ++ Runtime Library Linker Woes

Follow this close scenario, although it seems to coincide with my previous questions. However, I do not receive a response. Therefore, please do not report as duplicate.

I have a project that has 10 dependencies. First I compiled using the / MTD option in the C / C ++ cogeneration section in the main project, and all its dependencies are successfully compiled.

Then I changed the option from / MTD to / MDd and again all dependent projects get 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?

+2
source share
3 answers

You cannot mix C runtime libraries. If you have a library or object compiled by / MT (nothing), you cannot just reference / MD. You need to associate with thread safe MSVCRT. There is no, if only. You CANNOT mix C. runtime. I always found this best, even in programs that don't execute threads, just to use / MT.

Did you perform a project cleanup operation to delete already created objects and libraries? You also have a dependency on SQLite, have you rebuilt this too?

+5
source

When a bundle of a C ++ static library is bundled together, they should all have / MTD, or they should all have / MDd. You cannot link a project with / MTD to another project using / MDd

This is likely to cause binding errors. The reason you get it only in your main project is because your main project is the only one that is actually connected. Please let us know if your problem resolved.

I remember that I had the same problem with / MTD and / MDd, and I had very similar errors.

+1
source

My answer here may be useful, referring to some MSDN articles that I found very helpful in solving my version of this problem.

0
source

Source: https://habr.com/ru/post/1285726/


All Articles