c++nmakemapserverlnk2005mt

LNK2005: find the module which was built with /MT


I'm trying to build C++ project (mapserver). It depends on some other projects.

When I run nmake, it shows many errors like this:

...
LIBCMTD.lib(getenv.obj) : error LNK2005: _getenv already defined in MSVCRT.lib(MSVCR90.dll)
LIBCMTD.lib(tolower.obj) : error LNK2005: _tolower already defined in MSVCRT.lib(MSVCR90.dll)
LIBCMTD.lib(fflush.obj) : error LNK2005: _fflush already defined in MSVCRT.lib(MSVCR90.dll)
MSVCRT.lib(MSVCR90.dll) : error LNK2005: __strnicmp already defined in LIBCMTD.lib(strnicmp.obj)
...

I know it is caused by /MD and /MT options when they differs from project to project.

I checked all project's build files and have found only one with /MT. I changed it to /MD and rebuilt it, but error remained.

How to find a library caused this error?

Thanks for all!

P.S. Project list:

curl-7.24.0
expat-2.0.1
freetype-2.4.8
gdal-1.9.0
gdwin32
jpeg-6b
lpng158
mapserver <-- main
postgresql-8.4.9
proj-4.7.0
regex-0.12

zlib


Solution

  • The solution turned out very simple.

    I run dumpbin on each library that main program uses. One of them was compiled with

    /DEFAULTLIB:"LIBCMTD"
    

    that means /MT option.

    P.S. It is interesting, that build file didn't contain /MT or /MTd options. Instead, it included

    <win32.mak>
    

    with

    !IFDEF NODEBUG
    cvarsmt    = $(noansi) -D_MT -MT
    cvars      = $(cvarsmt)
    cvarsdll   = $(noansi) -D_MT -D_DLL -MD
    !ELSE
    cvarsmt    = $(noansi) -D_MT -MTd
    cvars      = $(cvarsmt)
    cvarsdll   = $(noansi) -D_MT -D_DLL -MDd
    !ENDIF
    

    The makefile contained

    CFLAGS= $(cflags) $(cdebug) $(cvars) -I.
    

    I replaced it with

    CFLAGS= $(cflags) $(cdebug) $(noansi) -D_MD -MDd -I.
    

    and all begun to work.