Community
cancel
Showing results for 
Search instead for 
Did you mean: 
Hansen__Mogens
Beginner
416 Views

LNK2038 mismatch detected for '_ITERATOR_DEBUG_LEVEL'

When using the Intel Math Library with Intel C++ 2018 and Visual C++ 2017 (15.5.7), there is a linker problem when using static linked runtime library because there is no debug version of the Intel Math libary for multithreaded static linking.

The question is whether the workaround (ignoring the libcpmt.lib) is robust

This sample code exposes the problem (when compiled with Debug Multi-threaded Static library (/MTd)

 

#include <iostream>
#include <vector>
#include <mutex>
#include <cstdlib>
#include <cmath>
 
// This application is build to expose a linker issue using the Intel 2018 C++ compiler on Windows
// using Debug build and static linked multi-thread runtime-library
//
// The issue is visible when using the Intel Math library and the Microsoft C++ run-time library
// An example of that is when using the std::sin (from the Intel Math Library) function and the std::mutex (from the Microsoft Runtime Library)
//
// From
// it is stated that there are no Intel Math Library for Debug Multi-Threaded (/MTd)
// Thus the Multi-threaded static Intel Math Library (/MT) (libmmt.lib) references the Microsoft Multi-threaded Static Release Library (libcpmt.lib),
// while the application references the Microsoft Multi-threaded static Debug Library (libcpmtd.lib)
//
// Thus there is a linker conflict.
//
// The linker errors are:
//   Error LNK2038 mismatch detected for '_ITERATOR_DEBUG_LEVEL': value '0' doesn't match value '2' in ConsoleApplication3.obj ConsoleApplication3 c:\Users\mhn\source\repos\ConsoleApplication3\libcpmt.lib(ppltasks.obj) 1
//   Error LNK2038 mismatch detected for 'RuntimeLibrary': value 'MT_StaticRelease' doesn't match value 'MTd_StaticDebug' in ConsoleApplication3.obj ConsoleApplication3 c:\Users\mhn\source\repos\ConsoleApplication3\libcpmt.lib(ppltasks.obj) 1
//   Error LNK2038 mismatch detected for '_ITERATOR_DEBUG_LEVEL': value '0' doesn't match value '2' in ConsoleApplication3.obj ConsoleApplication3 c:\Users\mhn\source\repos\ConsoleApplication3\libcpmt.lib(excptptr.obj) 1
//   Error LNK2038 mismatch detected for 'RuntimeLibrary': value 'MT_StaticRelease' doesn't match value 'MTd_StaticDebug' in ConsoleApplication3.obj ConsoleApplication3 c:\Users\mhn\source\repos\ConsoleApplication3\libcpmt.lib(excptptr.obj) 1
//
// The workaround is to add the library
//    libcpmt.lib
// to Ignore Specific Default Libraries
// But is this safe
 
 
 
// The muxtex sin_vector_mutex is redundant
// but it exposes a problem when building with the Intel 18 Compiler on Windows
std::mutex      sin_vector_mutex;
 
std::vector<double> sin( const std::vector<double>& values)
{
    std::lock_guard<std::mutex>     lock ( sin_vector_mutex );
    std::vector<double> result;
 
    for(const auto value : values)
    {
        result.push_back( std::sin(value) );
    }
 
    return result;
}
 
 
int main (int argc, char *argv[])
{
    if(argc < 2)
    {
        return EXIT_SUCCESS;
    }
 
    const std::vector<double>   values = [ argc, argv ]()
    {
        std::vector<double> result;
 
        for( int i = 1; argc != i; ++i)
        {
            const double    value = std::atof( argv );
            if( 0.0f != value )
            {
                result.push_back( value );
            }
        }
 
        return result;
    }();
 
    for(const auto value : values)
    {
        std::cout << value << std::endl;
    }
}
0 Kudos
0 Replies
Reply