I keep having linker errors of the following form:
libcmtd.dll msvmrtd.dll some element(ex: _mkdir ) already defined...
and I don't know how to resolve them.
Here is a complete error message:
private: __thiscall type_info::type_info(class type_info const &)" (??0type_info@@AAE@ABV0@@Z) already defined in LIBCMTD.lib(typinfo.obj)
MSVCRTD.lib(ti_inst.obj) : error LNK2005: "private: class type_info & __thiscall type_info::operator=(class type_info const &)" (??4type_info@@AAEAAV0@ABV0@@Z) already defined in LIBCMTD.lib(typinfo.obj)
Can you help me solve this issue?
Check a few things:
Are your header files guarded. I.e. do they have
#ifndef
guards.Are you defining (non-template) functions in headers without the
inline
keyword. That messes lots of stuff up.Are you trying to define templates in a .cpp file. All template definitions need to be in headers.
Post some code and exact error text please!
Your problem is that you're linking with two files providing the same symbol.
You haven't provided the real error message so we can't tell you exactly what the problem is but it's likely to be that you're linking with libraries from two different versions of Visual Studio.
There are also solutions available by searching the web (I assume you did this but just missed the articles in question :-) that suggest you can fix the problem by changing the project options from "Multi-threaded Debug(/MTd)"
to "Multi-threaded Debug DLL (/MTD)"
but I haven't looked in to this.
Please post the complete error so we can offer more targeted assistance.
Make sure the option you select for Runtime Libary linking is the same for every project and library. Project Properties -> Configuration Properties -> C/C++ -> Code Generation -> Runtime Library -> "Multi-threaded" / "Multi-threaded DLL" / ...
My issue was all of my C++ projects were "Multi-threaded" but I was referencing fortran modules that were "Multi-threaded DLL"
The MSDN article on LNK4098 has a very useful table: it tells you which libraries to manually add to the "Ignore specific library" list, depending on which CRT you're using. You need to pick a CRT (Multithreaded or not; static or DLL; debug or release), and then add the ignore libraries based on your choice.
The underlying cause is described in more detail in KB154753 ... libraries that a program will link with when built by using Visual C++
My interpretation of this is that in certain situations the algorithm that automatically picks which CRT libraries to link your code with will pick several conflicting libraries.
来源:https://stackoverflow.com/questions/949017/how-can-i-resolve-this-link-error-in-visual-studio-lnk2005