Summary of common errors in VC MFC compilation and connection

1. Error one

(1) Error example

  Error 4 error LNK2005: _DllMain@12 is already defined in MSVCRTD.lib(dllmain.obj) D:\work\codes\vad_sdk_soundrecord_ocx\vad_sdk_soundrecord_ocx\AsrControl\mfcs120ud.lib(dllmodul.obj) AsrControl

 Error 5 error LNK1169: One or more multiply defined symbols found D:\work\codes\vad_sdk_soundrecord_ocx\vad_sdk_soundrecord_ocx\bin\AsrControl.ocx 1 1 AsrControl

(2) Analysis

         Simply put, the project that produces the error uses both the CRT library and the MFC library, and the link sequence is wrong. The CRT library uses weak external links for the new, delete and DllMain functions. The MFC library also contains new, delete, and DllMain functions. These functions require that the MFC library be linked before the CRT library.

         The above error can be seen that when linking the library mfcs120ud.lib, it is found that _DllMain has been defined in MSVCRTD.lib

  In the "Project->Properties->Linker->Command Line" column, enter the /verbose:lib compilation parameter, so that you can see the sequence of libraries searched during linking in the output window. For this problem, you must You can see output similar to the following:

1> Searching for libraries
1> Searching for D:\work\codes\vad_sdk_soundrecord_ocx\vad_sdk_soundrecord_ocx\bin\libusc.lib: 
1> Searching for ..\gvad\gvad.lib: 
1> Searching for D:\Program Files (x86 )\Microsoft Visual Studio 12.0\VC\lib\msvcprtd.lib: 
1> Searching D:\Program Files (x86)\Microsoft Visual Studio 12.0\VC\lib\MSVCRTD.lib: 
1> Searching D:\Program Files (x86)\Microsoft Visual Studio 12.0\VC\lib\OLDNAMES.lib: 
1> Searching for D:\Program Files (x86)\Microsoft Visual Studio 12.0\VC\atlmfc\lib\mfc120ud.lib: 
1> Searching for D :\Program Files (x86)\Microsoft Visual Studio 12.0\VC\atlmfc\lib\mfcs120ud.lib: 

1>mfcs120ud.lib(dllmodul.obj) : error LNK2005: _DllMain@12 is already defined in MSVCRTD.lib(dllmain.obj)

       It can be seen from the above dependencies: the compiler first links the MSVCRTD.lib library, then links mfcs120ud.lib, and then reports an error when linking mfcs120ud.lib

(3) Solution

      Let the compiler link mfcs120ud.lib first, and then link MSVCRTD.lib to solve the problem

In "Project->Properties->Linker->Input->Additional Dependencies", append: mfcs120ud.lib; MSVCRTD.lib;

    Get it!


Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=324781303&siteId=291194637