Link error "LNK2005: __initterm_e already defined in MSVCRTD.lib(MSVCR100D.dll)" when using "/Qcheck-pointers:write" on Windows

Reference Number: DPD200241104

Products
Intel C++ Composer XE 2013 for Windows update 1 or update 2

Problem
Link error occurs with Intel C++ Compose XE 2013 for Windows update 1 and update 2 when using the Pointer Checker option "/Qcheck-pointers:xxx". As show below with a sample code:

>> type chello.cpp
#include <stdio.h> 
#include <string>
using namespace std;

int main(int argc, char* argv[])
{
	string strtest("Hello from string!");

    printf("%srn", strtest);
    return 0; 
}

>>icl -MDd -Od -Qcheck-pointers:write chello.cpp
Intel(R) C++ Compiler XE for applications running on IA-32, Version 13.1.0.149 Build 20130118
Copyright (C) 1985-2013 Intel Corporation.  All rights reserved.

chello.cpp
Microsoft (R) Incremental Linker Version 10.00.40219.01
Copyright (C) Microsoft Corporation.  All rights reserved.

-out:chello.exe
chello.obj
libcmt.lib(crt0dat.obj) : error LNK2005: __initterm_e already defined in MSVCRTD.lib(MSVCR100D.dll)
libcmt.lib(crt0dat.obj) : error LNK2005: _exit already defined in MSVCRTD.lib(MSVCR100D.dll)
libcmt.lib(crt0dat.obj) : error LNK2005: __exit already defined in MSVCRTD.lib(MSVCR100D.dll)
libcmt.lib(crt0dat.obj) : error LNK2005: __cexit already defined in MSVCRTD.lib(MSVCR100D.dll)
libcmt.lib(crt0dat.obj) : error LNK2005: __amsg_exit already defined in MSVCRTD.lib(MSVCR100D.dll)
libcmt.lib(invarg.obj) : error LNK2005: __invoke_watson already defined in MSVCRTD.lib(MSVCR100D.dll)
......
......


Root Cause

The Pointer Checker library "libchkpwrapmd_w.lib" is built with default libraries information included. So when linking it with the application, it brings in the libraries it needs. This library is only linked when you use the Pointer Checker option "/Qcheck-pointers:xxx".

Resolution
This issue has been worked on. When there is a fix, we will update this KB with the latest information. For now please use the workarounds provided below.
One workaround for now is to use "/MT" option instead like below:

>>icl -MT -Od -Qcheck-pointers:write chello.cpp
Intel(R) C++ Compiler XE for applications running on IA-32, Version 13.1.0.149 Build 20130118
Copyright (C) 1985-2013 Intel Corporation.  All rights reserved.

chello.cpp
Microsoft (R) Incremental Linker Version 10.00.40219.01
Copyright (C) Microsoft Corporation.  All rights reserved.

-out:chello.exe
chello.obj

Or

>>xilink /nodefaultlib:libcpmt /nodefaultlib:libcmt chello.obj
xilink: executing 'link'
Microsoft (R) Incremental Linker Version 10.00.40219.01
Copyright (C) Microsoft Corporation.  All rights reserved.

/nodefaultlib:libcpmt
/nodefaultlib:libcmt
chello.obj
   Creating library chello.lib and object chello.exp

>>

Another workaround is to use the Pointer Checker library "libchkpwrapmd_w.lib" from the Intel C++ Composer 2013 for Windows RTM package.

Для получения подробной информации о возможностях оптимизации компилятора обратитесь к нашему Уведомлению об оптимизации.