天天看点

LIBCMTD.lib问题

程序中用到了多线程,

如果想强行链接,中VS2005中如何设置?

以下为运行错误:

------ Build started: Project: WINThread, Configuration: Debug Win32 ------

Linking...

tinyxmld.lib(tinystr.obj) : warning LNK4075: ignoring '/EDITANDCONTINUE' due to '/OPT:ICF' specification

LIBCMTD.lib(dbgheap.obj) : error LNK2005: _malloc already defined in LIBCMT.lib(malloc.obj)

LIBCMTD.lib(dbgheap.obj) : error LNK2005: __heap_alloc already defined in LIBCMT.lib(malloc.obj)

LIBCMTD.lib(dbgheap.obj) : error LNK2005: _calloc already defined in LIBCMT.lib(calloc.obj)

LIBCMTD.lib(dbgheap.obj) : error LNK2005: _realloc already defined in LIBCMT.lib(realloc.obj)

LIBCMTD.lib(dbgheap.obj) : error LNK2005: __recalloc already defined in LIBCMT.lib(realloc.obj)

LIBCMTD.lib(dbgheap.obj) : error LNK2005: _free already defined in LIBCMT.lib(free.obj)

LIBCMTD.lib(dbgheap.obj) : error LNK2005: __msize already defined in LIBCMT.lib(msize.obj)

LIBCMTD.lib(malloc.obj) : error LNK2005: _V6_HeapAlloc already defined in LIBCMT.lib(malloc.obj)

LIBCMTD.lib(dbghook.obj) : error LNK2005: __crt_debugger_hook already defined in LIBCMT.lib(dbghook.obj)

LIBCMTD.lib(sbheap.obj) : error LNK2005: __get_sbh_threshold already defined in LIBCMT.lib(sbheap.obj)

LIBCMTD.lib(sbheap.obj) : error LNK2005: __set_sbh_threshold already defined in LIBCMT.lib(sbheap.obj)

LIBCMTD.lib(sbheap.obj) : error LNK2005: __set_amblksiz already defined in LIBCMT.lib(sbheap.obj)

LIBCMTD.lib(sbheap.obj) : error LNK2005: __get_amblksiz already defined in LIBCMT.lib(sbheap.obj)

LIBCMTD.lib(sbheap.obj) : error LNK2005: ___sbh_heap_init already defined in LIBCMT.lib(sbheap.obj)

LIBCMTD.lib(sbheap.obj) : error LNK2005: ___sbh_find_block already defined in LIBCMT.lib(sbheap.obj)

LIBCMTD.lib(sbheap.obj) : error LNK2005: ___sbh_free_block already defined in LIBCMT.lib(sbheap.obj)

LIBCMTD.lib(sbheap.obj) : error LNK2005: ___sbh_alloc_block already defined in LIBCMT.lib(sbheap.obj)

LIBCMTD.lib(sbheap.obj) : error LNK2005: ___sbh_alloc_new_region already defined in LIBCMT.lib(sbheap.obj)

LIBCMTD.lib(sbheap.obj) : error LNK2005: ___sbh_alloc_new_group already defined in LIBCMT.lib(sbheap.obj)

LIBCMTD.lib(sbheap.obj) : error LNK2005: ___sbh_resize_block already defined in LIBCMT.lib(sbheap.obj)

LIBCMTD.lib(sbheap.obj) : error LNK2005: ___sbh_heapmin already defined in LIBCMT.lib(sbheap.obj)

LIBCMTD.lib(sbheap.obj) : error LNK2005: ___sbh_heap_check already defined in LIBCMT.lib(sbheap.obj)

LIBCMTD.lib(sbheap.obj) : error LNK2005: ___sbh_pHeaderDefer already defined in LIBCMT.lib(sbheap.obj)

LIBCMTD.lib(isctype.obj) : error LNK2005: __isctype_l already defined in LIBCMT.lib(isctype.obj)

LIBCMTD.lib(isctype.obj) : error LNK2005: __isctype already defined in LIBCMT.lib(isctype.obj)

LINK : warning LNK4098: defaultlib 'LIBCMTD' conflicts with use of other libs; use /NODEFAULTLIB:library

C:/Documents and Settings/neusoft/My Documents/Visual Studio 2005/Projects/WINThread/Debug/WINThread.exe : fatal error LNK1169: one or more multiply defined symbols found

Build log was saved at "file://c:/Documents and Settings/neusoft/My Documents/Visual Studio 2005/Projects/WINThread/WINThread/Debug/BuildLog.htm"

WINThread - 26 error(s), 2 warning(s)

========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========

指定编译选项/MDd

并忽略LIBCMT.lib

右击工程--属性--配置属性--C/C++--代码生成--运行时库--多线程调试(/MDd)

右击工程--属性--配置属性--链接器--输入--忽略特定库

在你用到多线程的 .cpp 文件中加上一句:

#pragma comment(lib, "LIBCMT.LIB")

比如我的一个程序中使用的:

C/C++ code
#include 
        "
        D3Dapp.h
        "
        
#include 
        <
        process.h
        >
        

        #pragma
         comment(lib, "LIBCMT.LIB")
        


        //
        后台绘图线程
        

        void
         Paint(
        void
         
        *
         obj)
{
    C3Dapp 
        *
         C3Dobj 
        =
         (C3Dapp 
        *
        )obj;

    C3Dobj
        ->
        Render();
}

HRESULT C3Dapp ::InitSence()
{
    CUSTVERTEX 
        *
                        pWriteData;

    
        if
         (FAILED(m_lpD3dDevice
        ->
        CreateVertexBuffer(
        sizeof
        (CUSTVERTEX) 
        *
         
        3
        ,
    .............