본문 바로가기

Private/SW Programming

libcmtd.lib msvcrtd.lib 이건 뭡니까? 같은 겁니까? 다른 겁니까?

저는 주로 Linux 환경에서 빌드를 합니다만..

회사에서는 처음으로 VS2010 환경에서 작업을 하게 되었습니다.

기존에 있던 코드에 외부에서 제공한 라이브러리를 붙여서 빌드를 해야 하는데...

링크시에 오류가 나네요..

오류를 보니 제목과 같은 두개의 라이브러리가 충돌을 내고 있네요.

가진 재주가 없으니 남의 재주를 빌리기로 마음 먹고 인터넷을 뒤지기 시작합니다.

음..아래와 같은 사이트가 보이네요...

http://jellapi.net/jpidev/entry/해결방법-error-LNK2005-MSVCRTlib-LIBCMTDlib-nafxcwdlib

해결책은 알겠고...

그렇다면 이녀석들은 뭔데 링크 에러는 내는 것일까요?

http://msdn.microsoft.com/en-us/library/2kzt1wy3(v=vs.71).aspx

음..여기에 적절한 설명이 나와 있네요...

libcmtd.lib 는 MTd 옵션으로 빌드시에 사용하는 libc.lib 파일이고 msvcrtd.lib  파일은 MDd 옵션으로 빌드할때 필요한 libc.lib 파일인것이죠.. 

짧게 설명하면 서로 다른 환경에서 같은 함수를 제공하기 위해 만들어진 라이브러리들이 함께 포함되어 링크에러를 발생시켰습니다.

저같은 경우는 A 프로젝트에 B라는 새로운 라이브러리를 붙일때 문제가 생겼었는데요.

사실 B라는 라이브러리를 코드로 갖고 있었기 때문에 처음부터 옵션을 변경해서 A와 B 가 같은 조건으로 빌드하였기 때문에 문제가 나타나지 않았어야 했는데..

이전부터 A라는 과제에 포함되어 있던 A-1 이라는 라이브러리에서 충돌이 났었던 겁니다.

A라는 과제는 MDd로 B라는 라이브러리도 MDd로 빌드되었었는데요...실은 A-1 라이브러리는 MTd로 빌드되어 이전부터 포함되어 있었던것죠..그것도 모르고 다른 곳만 뒤졌던 거에요..ㅜㅜ

 

 

아래는 "http://msdn.microsoft.com/en-us/library/2kzt1wy3(v=vs.71).aspx" 에서 퍼온겁니다.

Option Description
/MD Defines _MT and _DLL so that both multithread- and DLL-specific versions of the run-time routines are selected from the standard .h files. This option also causes the compiler to place the library name MSVCRT.lib into the .obj file.

Applications compiled with this option are statically linked to MSVCRT.lib. This library provides a layer of code that allows the linker to resolve external references. The actual working code is contained in MSVCR71.DLL, which must be available at run time to applications linked with MSVCRT.lib.

When /MD is used with _STATIC_CPPLIB defined (/D_STATIC_CPPLIB) it will cause the application to link with the static multithread Standard C++ Library (libcpmt.lib) instead of the dynamic version (msvcprt.lib) while still dynamically linking to the main CRT via msvcrt.lib.

/MDd Defines _DEBUG, _MT, and _DLL so that debug multithread- and DLL-specific versions of the run-time routines are selected from the standard .h files. It also causes the compiler to place the library name MSVCRTD.lib into the .obj file.
/ML Causes the compiler to place the library name LIBC.lib into the .obj file so that the linker will use LIBC.lib to resolve external symbols. This is the compiler's default action. LIBC.lib does not provide multithread support.
/MLd Defines _DEBUG and causes the compiler to place the library name LIBCD.lib into the .obj file so that the linker will use LIBCD.lib to resolve external symbols. LIBCD.lib does not provide multithread support.
/MT Defines _MT so that multithread-specific versions of the run-time routines are selected from the standard header (.h) files. This option also causes the compiler to place the library name LIBCMT.lib into the .obj file so that the linker will use LIBCMT.lib to resolve external symbols. Either /MT or /MD (or their debug equivalents /MTd or /MDd) is required to create multithreaded programs.
/MTd Defines _DEBUG and _MT. Defining _MT causes multithread-specific versions of the run-time routines to be selected from the standard .h files. This option also causes the compiler to place the library name LIBCMTD.lib into the .obj file so that the linker will use LIBCMTD.lib to resolve external symbols. Either /MTd or /MDd (or their non-debug equivalents /MT or MD) is required to create multithreaded programs.
/LD Creates a DLL.

Passes the /DLL option to the linker. The linker looks for, but does not require, a DllMain function. If you do not write a DllMain function, the linker inserts a DllMain function that returns TRUE.

Links the DLL startup code.

Creates an import library (.lib), if an export (.exp) file is not specified on the command line; you link the import library to applications that call your DLL.

Interprets /Fe as naming a DLL rather than an .exe file; the default program name becomes basename.dll instead of basename.exe.

Changes the default run-time library support to /MT if you have not explicitly specified one of the /M options.

/LDd Creates a debug DLL. Defines _DEBUG.