LNK2038,MSVS2017 MAGMA的原因列表

时间:2018-11-03 14:09:42

标签: c++ cmake visual-studio-2017 magma

我的目标是通过编译(无济于事)LNK2038“检测到'_ITERATOR_DEBUG_LEVEL'的不匹配:值'0'与值'2'不匹配”的原因列表,其他人可能有条不紊地按照其自身的情况进行调试,我的情况会得到解决

我的情况:

要求:

  • Windows 10
  • CMake
  • MSVS 2017
  • 英特尔Paralax Studio XE
  • CUDA

要复制:

  1. 下载MAGMA
  2. 运行CMake GUI

    • 手动设置GPU_TARGET=Pascal(我的卡:GeForce GTX 1070计算能力:6.1)
    • 手动设置MKLROOT=D:/Program Files (x86)/IntelSWTools/parallel_studio_xe_2019.0.045/compilers_and_libraries_2019/windows/mkl(按照README-Windows的说明)
    • LAPACK_LIBRARIES:使用https://software.intel.com/en-us/articles/intel-mkl-link-line-advisor确定

      • My choice
      • D:/Program Files (x86)/IntelSWTools/parallel_studio_xe_2019.0.045/compilers_and_libraries_2019/windows/mkl/lib/intel64_win/mkl_intel_lp64.lib;D:/Program Files (x86)/IntelSWTools/parallel_studio_xe_2019.0.045/compilers_and_libraries_2019/windows/mkl/lib/intel64_win/mkl_intel_thread.lib;D:/Program Files (x86)/IntelSWTools/parallel_studio_xe_2019.0.045/compilers_and_libraries_2019/windows/mkl/lib/intel64_win/mkl_core.lib;D:/Program Files (x86)/IntelSWTools/compilers_and_libraries_2019.0.117/windows/compiler/lib/intel64_win/libiomp5md.lib
  3. 从生成的VS解决方案中,以 Debug模式 magma magma_sparse 项目进行编译(无需编译600+测试项目)

  4. 在单独的文件夹中,将example codeCMakeLists.txt

    add_executable(magma-test example_sparse.cpp)
    
    find_package( CUDA ) # just to set CUDA_INCLUDE_DIRS
    
    target_include_directories(magma-test PUBLIC D:/Work/Magma/magma-2.4.0/include D:/Work/Magma/magma-2.4.0/sparse/include ${CUDA_INCLUDE_DIRS})
    target_link_libraries(magma-test debug D:/Work/Magma/magma-2.4.0/build/lib/Debug/magma.lib debug D:/Work/Magma/magma-2.4.0/build/lib/Debug/magma_sparse.lib)
    
    set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} /MT")
    set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} /MTd")
    
  5. 运行CMake(配置,生成)

  6. 打开VS解决方案,并以 Debug模式
  7. 进行编译

问题结果:

1>magma_sparse.lib(magma_sparse_generated_djacobisetup.cu.obj) : error LNK2038: mismatch detected for '_ITERATOR_DEBUG_LEVEL': value '0' doesn't match value '2' in magma.lib(interface.obj)

1>magma_sparse.lib(magma_sparse_generated_djacobisetup.cu.obj) : error LNK2038: mismatch detected for 'RuntimeLibrary': value 'MT_StaticRelease' doesn't match value 'MTd_StaticDebug' in magma.lib(interface.obj)

----------

要检查LNK2038的事项:

  1. 所有依赖项(* .lib文件)均使用相同的“ Debug / Release”标志进行编译
    • 再次检查右键单击项目->属性->链接器->输入->其他依赖项
    • 实际使用的依赖项
    • 转到每个依赖项项目和您的项目,并通过右键单击“项目”->“属性”->“ C / C ++”->“代码生成”->“运行时库”来检查构建标志

1 个答案:

答案 0 :(得分:0)

“解决”上述错误,编译并运行的CMakeLists.txt是:

add_executable(magma-test example_sparse.cpp)

find_package( CUDA ) 
set( MKLROOT "D:/Program Files (x86)/IntelSWTools/parallel_studio_xe_2019.0.045/compilers_and_libraries_2019/windows/mkl" )
set( LAPACK_LIBRARIES 
   "D:/Program Files (x86)/IntelSWTools/parallel_studio_xe_2019.0.045/compilers_and_libraries_2019/windows/mkl/lib/intel64_win/mkl_intel_lp64.lib"
   "D:/Program Files (x86)/IntelSWTools/parallel_studio_xe_2019.0.045/compilers_and_libraries_2019/windows/mkl/lib/intel64_win/mkl_intel_thread.lib"
   "D:/Program Files (x86)/IntelSWTools/parallel_studio_xe_2019.0.045/compilers_and_libraries_2019/windows/mkl/lib/intel64_win/mkl_core.lib"
   "D:/Program Files (x86)/IntelSWTools/compilers_and_libraries_2019.0.117/windows/compiler/lib/intel64_win/libiomp5md.lib")

target_include_directories(magma-test PUBLIC 
   "D:/Work/Magma/magma-2.4.0/include" 
   "D:/Work/Magma/magma-2.4.0/sparse/include" 
   ${CUDA_INCLUDE_DIRS}
   ${MKLROOT}/include)
target_link_libraries(magma-test 
   ${CUDA_CUDART_LIBRARY}
   ${CUDA_CUBLAS_LIBRARIES}
   ${CUDA_cusparse_LIBRARY}
   ${LAPACK_LIBRARIES}
   debug D:/Work/Magma/magma-2.4.0/build/lib/Debug/magma.lib 
   debug D:/Work/Magma/magma-2.4.0/build/lib/Debug/magma_sparse.lib
   optimized D:/Work/Magma/magma-2.4.0/build/lib/Release/magma.lib 
   optimized D:/Work/Magma/magma-2.4.0/build/lib/Release/magma_sparse.lib)

set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} /MT")
set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} /MTd")

对于使用MAGMA库的代码,似乎还必须提供MAGMA在编译时使用的CUDA和MKL库。

编辑:不,不。它是在Release中编译并运行的,而不是在Debug中运行的。