我想在所写的ATL DLL COM组件中使用C的动态分配函数realloc()以及free(),并想使用文件处理函数fopen()以及fclose()等。此时,编译时出现了如下错误提示。初步看,自己的理解是两个静态库的定义出现了冲突。请各位请点迷津。谢谢了。
如下是链接时的出错信息:
MSVCRT.lib(MSVCRT.dll) : error LNK2005: _free already defined in LIBCMTD.lib(dbgheap.obj)
MSVCRT.lib(MSVCRT.dll) : error LNK2005: _malloc already defined in LIBCMTD.lib(dbgheap.obj)
MSVCRT.lib(MSVCRT.dll) : error LNK2005: _realloc already defined in LIBCMTD.lib(dbgheap.obj)
MSVCRT.lib(MSVCRT.dll) : error LNK2005: _fopen already defined in LIBCMTD.lib(fopen.obj)
MSVCRT.lib(MSVCRT.dll) : error LNK2005: _fclose already defined in LIBCMTD.lib(fclose.obj)
MSVCRT.lib(MSVCRT.dll) : error LNK2005: _fread already defined in LIBCMTD.lib(fread.obj)
MSVCRT.lib(MSVCRT.dll) : error LNK2005: _fwrite already defined in LIBCMTD.lib(fwrite.obj)
MSVCRT.lib(MSVCRT.dll) : error LNK2005: _fseek already defined in LIBCMTD.lib(fseek.obj)
MSVCRT.lib(MSVCRT.dll) : error LNK2005: _ftell already defined in LIBCMTD.lib(ftell.obj)
MSVCRT.lib(MSVCRT.dll) : error LNK2005: _fflush already defined in LIBCMTD.lib(fflush.obj)
MSVCRT.lib(MSVCRT.dll) : error LNK2005: _fputc already defined in LIBCMTD.lib(fputc.obj)
MSVCRT.lib(MSVCRT.dll) : error LNK2005: _getc already defined in LIBCMTD.lib(fgetc.obj)
MSVCRT.lib(MSVCRT.dll) : error LNK2005: _strncpy already defined in LIBCMTD.lib(strncpy.obj)
MSVCRT.lib(MSVCRT.dll) : error LNK2005: _calloc already defined in LIBCMTD.lib(dbgheap.obj)
MSVCRT.lib(MSVCRT.dll) : error LNK2005: _strncmp already defined in LIBCMTD.lib(strncmp.obj)
MSVCRT.lib(MSVCRT.dll) : error LNK2005: _sprintf already defined in LIBCMTD.lib(sprintf.obj)
MSVCRT.lib(MSVCRT.dll) : error LNK2005: __isctype already defined in LIBCMTD.lib(isctype.obj)
MSVCRT.lib(MSVCRT.dll) : error LNK2005: _abort already defined in LIBCMTD.lib(abort.obj)
MSVCRT.lib(MSVCRT.dll) : error LNK2005: _fprintf already defined in LIBCMTD.lib(fprintf.obj)
MSVCRT.lib(MSVCRT.dll) : error LNK2005: _memmove already defined in LIBCMTD.lib(memmove.obj)
MSVCRT.lib(MSVCRT.dll) : error LNK2005: _atoi already defined in LIBCMTD.lib(atox.obj)
MSVCRT.lib(MSVCRT.dll) : error LNK2005: _strchr already defined in LIBCMTD.lib(strchr.obj)
MSVCRT.lib(MSVCRT.dll) : error LNK2005: _exit already defined in LIBCMTD.lib(crt0dat.obj)
MSVCRT.lib(MSVCRT.dll) : error LNK2005: _getenv already defined in LIBCMTD.lib(getenv.obj)
MSVCRT.lib(MSVCRT.dll) : error LNK2005: __open already defined in LIBCMTD.lib(open.obj)
MSVCRT.lib(MSVCRT.dll) : error LNK2005: __setmode already defined in LIBCMTD.lib(setmode.obj)
MSVCRT.lib(MSVCRT.dll) : error LNK2005: __read already defined in LIBCMTD.lib(read.obj)
MSVCRT.lib(MSVCRT.dll) : error LNK2005: __write already defined in LIBCMTD.lib(write.obj)
MSVCRT.lib(MSVCRT.dll) : error LNK2005: __lseek already defined in LIBCMTD.lib(lseek.obj)
MSVCRT.lib(MSVCRT.dll) : error LNK2005: __close already defined in LIBCMTD.lib(close.obj)
MSVCRT.lib(MSVCRT.dll) : warning LNK4006: _free already defined in LIBCMTD.lib(dbgheap.obj); second definition ignored
MSVCRT.lib(MSVCRT.dll) : warning LNK4006: _malloc already defined in LIBCMTD.lib(dbgheap.obj); second definition ignored
MSVCRT.lib(MSVCRT.dll) : warning LNK4006: _realloc already defined in LIBCMTD.lib(dbgheap.obj); second definition ignored
MSVCRT.lib(MSVCRT.dll) : warning LNK4006: _fopen already defined in LIBCMTD.lib(fopen.obj); second definition ignored
MSVCRT.lib(MSVCRT.dll) : warning LNK4006: _fclose already defined in LIBCMTD.lib(fclose.obj); second definition ignored
MSVCRT.lib(MSVCRT.dll) : warning LNK4006: _fread already defined in LIBCMTD.lib(fread.obj); second definition ignored
MSVCRT.lib(MSVCRT.dll) : warning LNK4006: _fwrite already defined in LIBCMTD.lib(fwrite.obj); second definition ignored
MSVCRT.lib(MSVCRT.dll) : warning LNK4006: _fseek already defined in LIBCMTD.lib(fseek.obj); second definition ignored
MSVCRT.lib(MSVCRT.dll) : warning LNK4006: _ftell already defined in LIBCMTD.lib(ftell.obj); second definition ignored
MSVCRT.lib(MSVCRT.dll) : warning LNK4006: _fflush already defined in LIBCMTD.lib(fflush.obj); second definition ignored
MSVCRT.lib(MSVCRT.dll) : warning LNK4006: _fputc already defined in LIBCMTD.lib(fputc.obj); second definition ignored
MSVCRT.lib(MSVCRT.dll) : warning LNK4006: _getc already defined in LIBCMTD.lib(fgetc.obj); second definition ignored
MSVCRT.lib(MSVCRT.dll) : warning LNK4006: _strncpy already defined in LIBCMTD.lib(strncpy.obj); second definition ignored
MSVCRT.lib(MSVCRT.dll) : warning LNK4006: _calloc already defined in LIBCMTD.lib(dbgheap.obj); second definition ignored
MSVCRT.lib(MSVCRT.dll) : warning LNK4006: _strncmp already defined in LIBCMTD.lib(strncmp.obj); second definition ignored
MSVCRT.lib(MSVCRT.dll) : warning LNK4006: _sprintf already defined in LIBCMTD.lib(sprintf.obj); second definition ignored
MSVCRT.lib(MSVCRT.dll) : warning LNK4006: __isctype already defined in LIBCMTD.lib(isctype.obj); second definition ignored
MSVCRT.lib(MSVCRT.dll) : warning LNK4006: _abort already defined in LIBCMTD.lib(abort.obj); second definition ignored
MSVCRT.lib(MSVCRT.dll) : warning LNK4006: _fprintf already defined in LIBCMTD.lib(fprintf.obj); second definition ignored
MSVCRT.lib(MSVCRT.dll) : warning LNK4006: _memmove already defined in LIBCMTD.lib(memmove.obj); second definition ignored
MSVCRT.lib(MSVCRT.dll) : warning LNK4006: _atoi already defined in LIBCMTD.lib(atox.obj); second definition ignored
MSVCRT.lib(MSVCRT.dll) : warning LNK4006: _strchr already defined in LIBCMTD.lib(strchr.obj); second definition ignored
MSVCRT.lib(MSVCRT.dll) : warning LNK4006: _exit already defined in LIBCMTD.lib(crt0dat.obj); second definition ignored
MSVCRT.lib(MSVCRT.dll) : warning LNK4006: _getenv already defined in LIBCMTD.lib(getenv.obj); second definition ignored
MSVCRT.lib(MSVCRT.dll) : warning LNK4006: __open already defined in LIBCMTD.lib(open.obj); second definition ignored
MSVCRT.lib(MSVCRT.dll) : warning LNK4006: __setmode already defined in LIBCMTD.lib(setmode.obj); second definition ignored
MSVCRT.lib(MSVCRT.dll) : warning LNK4006: __read already defined in LIBCMTD.lib(read.obj); second definition ignored
MSVCRT.lib(MSVCRT.dll) : warning LNK4006: __write already defined in LIBCMTD.lib(write.obj); second definition ignored
MSVCRT.lib(MSVCRT.dll) : warning LNK4006: __lseek already defined in LIBCMTD.lib(lseek.obj); second definition ignored
MSVCRT.lib(MSVCRT.dll) : warning LNK4006: __close already defined in LIBCMTD.lib(close.obj); second definition ignored
   Creating library Debug/ContactQQ.lib and object Debug/ContactQQ.exp
LINK : warning LNK4098: defaultlib "MSVCRT" conflicts with use of other libs; use /NODEFAULTLIB:library
LINK : warning LNK4098: defaultlib "MSVCRTD" conflicts with use of other libs; use /NODEFAULTLIB:library
Debug/ContactQQ.dll : fatal error LNK1169: one or more multiply defined symbols found
Error executing link.exe.

解决方案 »

  1.   

    When the C Run-Time (CRT) library and Microsoft Foundation Class (MFC) libraries are linked in the wrong order, LNK2005 errors similar to the following may occur:
    CAUSE
    The CRT libraries use weak external linkage for the new, delete, and DllMain functions. The MFC libraries also contain new, delete, and DllMain functions, which requires MFC to be linked before the CRT libraries. RESOLUTION
    There are two ways to resolve this problem. The first solution involves forcing the linker to link the libraries in the correct order. The second solution allows you to find the module that is causing the problem and correct it. Solution One: Force Linker to Link Libraries in Correct Order
    Open the Project Settings dialog box by clicking Settings on the Build menu. 
    In the Settings For view, click to select (highlight) the project configuration that is getting the link errors. 
    Click the Link tab. 
    Click to select INPUT in the Category combo box. 
    In the Libraries to Ignore edit box, insert the library names (for example, Nafxcwd.lib Libcmtd.lib). NOTE: The linker command-line equivalent in /NOD:<library name>. 
    In the Object/library Modules edit box, insert the library names. You must ensure that these are listed in order and as the first two libraries in the line (for example, Nafxcwd.lib Libcmtd.lib). 
    Solution Two: Locate and Correct the Problem Module
    Perform the following steps to view the current library link order: 
    Open the Project Settings dialog box by clicking Settings on the Build menu. 
    In the Settings For view, click to select (highlight) the project configuration that is getting the link errors. 
    Click the Link tab. 
    Type the following in the Project Options dialog box:
    /verbose:lib
    Rebuild your project. The libraries will be listed in the output window during the linking process.