Sign in with Microsoft
Sign in or create an account.
Hello,
Select a different account.
You have multiple accounts
Choose the account you want to sign in with.

Summary

When you build a DLL by using the 64-bit version of the Microsoft Visual C++ Compiler and Linker, you may receive Linker error number LNK4197 if a function has been declared for export more than one time.

Symptoms

The Linker output may be similar to the following:

C:\>link /NOLOGO /def:Sample.def /pdb:Sample.pdb /out:Sample.dll  Sample.obj
Sample.obj : warning LNK4197: export 'DllSample' specified multiple times; using first specification
Creating library Sample.lib and object Sample.exp

Cause

The Linker error number LNK4197 is generated when a function has been declared for export more than one time. A function is declared for export in one of the following ways:

  • The function is declared by using the __declspec(dllexport) keyword in your C source file:

    __declspec(dllexport) int DllSample() 
    {
    return 42;
    }
  • The function is declared by using a module-definition (.DEF) file:

    EXPORTS
    DllSample

This Linker error may occur most frequently when both the __declspec(dllexport) keyword and a .DEF file are used to define the same function name in a .DLL project.

Resolution

To resolve this behavior, define exported functions only one time, either by using the __declspec(dllexport) keyword or by using a .DEF file. Do not use both of these methods.

Status

This behavior is by design.

More Information

Declaring a function for export more than one time may not produce the Linker error that is described in the "Symptoms" section of this article in 32-bit versions of the Microsoft Windows C++ Compiler and Linker. However, Microsoft recommends that you define function exports only one time in both 32-bit and 64-bit versions of the Windows C++ Compiler and Linker.

Need more help?

Want more options?

Explore subscription benefits, browse training courses, learn how to secure your device, and more.

Communities help you ask and answer questions, give feedback, and hear from experts with rich knowledge.

Was this information helpful?

What affected your experience?
By pressing submit, your feedback will be used to improve Microsoft products and services. Your IT admin will be able to collect this data. Privacy Statement.

Thank you for your feedback!

×