• Javascript
  • Python
  • Go

Duplicate _DllMain@12 definition in MSVCRT.lib: error LNK2005

When working with Microsoft Visual Studio, it is not uncommon to encounter various errors and issues during the development process. One suc...

When working with Microsoft Visual Studio, it is not uncommon to encounter various errors and issues during the development process. One such error, the "Duplicate _DllMain@12 definition in MSVCRT.lib: error LNK2005," can be quite frustrating and may cause a significant delay in your project. In this article, we will discuss what this error means, its possible causes, and how to resolve it.

First, let's understand what the error message is trying to tell us. "Duplicate _DllMain@12 definition" refers to a function called "DllMain" with a parameter value of 12, which is defined in two or more libraries. The "MSVCRT.lib" part indicates that the duplicate definition is found in the Microsoft C Runtime Library. And finally, the "LNK2005" error code means that the linker has encountered a duplicate symbol during the linking process.

The most common cause of this error is when two or more libraries have the same function name and parameter value. This can happen if you are using multiple third-party libraries in your project, and some of them have a function with the same name and parameter. When the linker tries to link these libraries together, it will encounter a conflict and throw the LNK2005 error.

To resolve this issue, there are a few steps you can take. The first and most straightforward solution is to rename the conflicting function in one of the libraries. This will ensure that there is no longer a duplicate definition, and the linker will be able to successfully link the libraries without any errors.

If renaming the function is not an option, you can try using the /FORCE:MULTIPLE linker option. This option allows multiple definitions of the same function to coexist, and the linker will choose one of them based on the order in which they are encountered. While this may resolve the error, it is not considered a best practice and may cause unexpected behavior in your program.

Another solution is to use the /OPT:REF linker option. This option will remove any unreferenced functions from the final executable, which may include the duplicate function. However, this is not a guaranteed solution as the function may be referenced indirectly, and the error may still persist.

If none of the above solutions work, you can try using the /NODEFAULTLIB linker option. This option will exclude the specified library from the linking process, which may help resolve the error. However, this option should be used with caution as it may result in unresolved external symbols and cause other errors.

In addition to these solutions, you can also try updating the libraries in your project to their latest versions. This may fix the issue if it was caused by a bug in the previous version of the library.

In some cases, the error may not be caused by a duplicate function, but rather a duplicate global variable or class. In such cases, the same solutions may apply, and you will need to rename or exclude the conflicting symbols from the linking process.

In conclusion, the "Duplicate _DllMain@12 definition in MSVCRT.lib: error LNK2005" is a common error encountered by developers using Microsoft Visual Studio. It is caused by a duplicate definition of a function, global variable, or class in two or more libraries. The best way to resolve this error is to rename the conflicting symbol or use linker options such as /FORCE:MULTIPLE or /NODEFAULTLIB. Keeping your third-party libraries up-to-date can also help

Related Articles