【问题标题】:How to instruct CMAKE to use Intel MKL in Visual Studio如何指示 CMAKE 在 Visual Studio 中使用英特尔 MKL
【发布时间】:2018-09-15 06:49:52
【问题描述】:

我正在尝试创建一个CMAKE 来构建一个Visual Studio 2017 x64 解决方案,其中我使用一些Intel MKL 函数来计算使用LU decomposition 的一般矩阵的逆。构建项目时出现以下错误:

Error   LNK2005 mkl_serv_allocate already defined in mkl_intel_thread_dll.lib(mkl_intel_thread.dll) test    C:\Users\user1\test\build\mkl_core.lib(mkl_memory_patched.obj)  
Error   LNK2005 mkl_serv_malloc already defined in mkl_intel_thread_dll.lib(mkl_intel_thread.dll)   test    C:\Users\user1\test\build\mkl_core.lib(mkl_memory_patched.obj)  
Error   LNK2005 mkl_serv_deallocate already defined in mkl_intel_thread_dll.lib(mkl_intel_thread.dll)   test    C:\Users\user1\test\build\mkl_core.lib(mkl_memory_patched.obj)  
Error   LNK2005 mkl_serv_free already defined in mkl_intel_thread_dll.lib(mkl_intel_thread.dll) test    C:\Users\user1\test\build\mkl_core.lib(mkl_memory_patched.obj)  
Error   LNK2005 mkl_serv_format_print already defined in mkl_intel_thread_dll.lib(mkl_intel_thread.dll) test    C:\Users\user1\test\build\mkl_core.lib(mkl_msg_support.obj) 
Error   LNK2005 mkl_serv_inspector_suppress already defined in mkl_intel_thread_dll.lib(mkl_intel_thread.dll)   test    C:\Users\user1\test\build\mkl_core.lib(mkl_semaphore.obj)   
Error   LNK2005 mkl_serv_inspector_unsuppress already defined in mkl_intel_thread_dll.lib(mkl_intel_thread.dll) test    C:\Users\user1\test\build\mkl_core.lib(mkl_semaphore.obj)   
Error   LNK2005 mkl_serv_thread_yield already defined in mkl_intel_thread_dll.lib(mkl_intel_thread.dll) test    C:\Users\user1\test\build\mkl_core.lib(mkl_semaphore.obj)   
Error   LNK2005 mkl_serv_unlock already defined in mkl_intel_thread_dll.lib(mkl_intel_thread.dll)   test    C:\Users\user1\test\build\mkl_core.lib(mkl_semaphore.obj)   


Error   LNK2019 unresolved external symbol __kmpc_global_thread_num referenced in function mkl_lapack_dgetrf    test    C:\Users\test\build\mkl_intel_thread.lib(dgetrf_par.obj)    
Error   LNK2001 unresolved external symbol __kmpc_global_thread_num test    C:\Users\test\build\mkl_intel_thread.lib(d__scal_drv.obj)   
Error   LNK2019 unresolved external symbol __kmpc_ok_to_fork referenced in function mkl_lapack_dgetrf   test    C:\Users\test\build\mkl_intel_thread.lib(dgetrf_par.obj)    
Error   LNK2001 unresolved external symbol __kmpc_ok_to_fork    test    C:\Users\test\build\mkl_intel_thread.lib(d__scal_drv.obj)   
Error   LNK2019 unresolved external symbol __kmpc_push_num_threads referenced in function mkl_lapack_dgetrf test    C:\Users\test\build\mkl_intel_thread.lib(dgetrf_par.obj)    
Error   LNK2001 unresolved external symbol __kmpc_push_num_threads  test    C:\Users\test\build\mkl_intel_thread.lib(d__scal_drv.obj)   
Error   LNK2019 unresolved external symbol __kmpc_fork_call referenced in function mkl_lapack_dgetrf    test    C:\Users\test\build\mkl_intel_thread.lib(dgetrf_par.obj)    
Error   LNK2001 unresolved external symbol __kmpc_fork_call test    C:\Users\test\build\mkl_intel_thread.lib(d__scal_drv.obj)   
Error   LNK2019 unresolved external symbol __kmpc_serialized_parallel referenced in function mkl_lapack_dgetrf  test    C:\Users\test\build\mkl_intel_thread.lib(dgetrf_par.obj)    
Error   LNK1120 16 unresolved externals test    C:\Users\user1\test\build\Debug\test.exe

这是因为下面的CMAKE吗?

cmake_minimum_required(VERSION 3.11)

PROJECT(MYPROJECT)

set(MKL_INCLUDE_DIRS "C:/Program Files (x86)/IntelSWTools/compilers_and_libraries/windows/mkl/include")
set(MKL_LIBRARIES "C:/Program Files (x86)/IntelSWTools/compilers_and_libraries/windows/mkl/lib/intel64")

include_directories(${MKL_INCLUDE_DIRS})

add_executable(test MACOSX_BUNDLE)

target_link_libraries(
            test
            ${MKL_LIBRARIES}/mkl_blas95_ilp64.lib"
            ${MKL_LIBRARIES}/mkl_blas95_lp64.lib"
            ${MKL_LIBRARIES}/mkl_core.lib"
            ${MKL_LIBRARIES}/mkl_core_dll.lib"
            ${MKL_LIBRARIES}/mkl_intel_ilp64.lib"
            ${MKL_LIBRARIES}/mkl_intel_ilp64_dll.lib"
            ${MKL_LIBRARIES}/mkl_intel_lp64.lib"
            ${MKL_LIBRARIES}/mkl_intel_lp64_dll.lib"
            ${MKL_LIBRARIES}/mkl_intel_thread.lib"
            ${MKL_LIBRARIES}/mkl_intel_thread_dll.lib"
            ${MKL_LIBRARIES}/mkl_lapack95_ilp64.lib"
            ${MKL_LIBRARIES}/mkl_lapack95_lp64.lib"
            ${MKL_LIBRARIES}/mkl_rt.lib"
            ${MKL_LIBRARIES}/mkl_sequential.lib"
            ${MKL_LIBRARIES}/mkl_sequential_dll.lib"
            ${MKL_LIBRARIES}/mkl_tbb_thread.lib"
            ${MKL_LIBRARIES}/mkl_tbb_thread_dll.lib"

我在系统PATH中有包含DLLs的bin文件夹:

C:\Program Files (x86)\IntelSWTools\compilers_and_libraries_2019.0.117\windows\redist\intel64_win\mkl

【问题讨论】:

  • 如何将详细的错误消息添加到您的问题中。除非我们知道未解析的符号是什么,否则很难提供帮助。
  • 我不知道答案,但很明显你有错误的库列表。你已经包含了一些你不应该有的,这就是为什么你有“已经定义”的错误消息,而错过了一些你需要的,这就是为什么你有“未解决”的错误消息。我认为需要好好看看 MKL 文档。
  • 您正在链接同一个库的 4 个变体。仅链接静态或动态以及 ilp64 或 lp64,具体取决于您的平台。

标签: c++ visual-studio visual-c++ cmake intel-mkl


【解决方案1】:

你链接了一些不必要的东西。您可以通过设置链接标志来解决此错误。

LINK_FLAGS "/force:multiple"

你丢失了一些必要的东西,请链接libiomp***.dllYou can refer to this post

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2022-07-06
    • 2018-02-21
    • 1970-01-01
    • 2015-02-21
    • 2016-07-14
    • 2016-09-26
    • 2019-11-19
    相关资源
    最近更新 更多