How to fix this link error in Visual Studio (LNK2005)?

I save the linker errors as follows:

libcmtd.dll msvmrtd.dll some element (ex: _mkdir) is already defined ...

and I don’t know how to resolve them.

Here is the 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 problem?

+4
source share
4 answers

Check out a few things:

  • Are your header files saved. That is, they have #ifndef security devices.

  • You define (non-template) functions in headers without the inline . It gets confused a lot of things.

  • You are trying to define patterns in a .cpp file. All template definitions should be in the headers.

Send the code and the text of the exact error, please!

+8
source

Your problem is that you are linking to two files with the same character.

You did not provide a real error message, so we cannot tell you exactly what the problem is, but you are probably linking to libraries from two different versions of Visual Studio.

There are also solutions available when searching on the Internet (I assume you did this, but just skipped the articles in question :-), which offer to fix the problem by changing the project settings from "Multi-threaded Debug(/MTd)" to the "Multi-threaded Debug DLL (/MTD)" , but I didn’t look at it.

Please post the full error so that we can offer more focused help.

+4
source

Make sure that the option selected for the Runtime Libary link is the same for each project and library. Project Properties → Configuration Properties → C / C ++ → Code Generation → Runtime Library → “Multithreaded” / “Multithreaded DLL” / ...

My problem was that all my C ++ projects were "multi-threaded", but I was referring to fortran modules that were "multi-threaded DLLs"

+2
source

The MSDN article on LNK4098 has a very useful table: it tells you which libraries to manually add to the "Ignore a specific library" list, depending on which CRT you use. You need to select CRT (multi-threaded or non-static or DLL; debugging or release), and then add the ignore libraries of your choice.

The main reason is described in more detail in KB154753 ... libraries that the program will be associated with when building using Visual C ++

My interpretation is that in certain situations, an algorithm that automatically selects which CRT libraries to link your code to select several conflicting libraries.

+1
source

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


All Articles