我正在尝试运行英特尔数学内核库(mkl)。有一个工具(https://software.intel.com/en-us/articles/intel-mkl-link-line-advisor)打印必要的,与环境有关的cmd命令,以将其用于C ++脚本编写。对我来说,它说:

使用此链接行:
 $ {MKLROOT} /lib/libmkl_intel_lp64.a $ {MKLROOT} /lib/libmkl_intel_thread.a $ {MKLROOT} /lib/libmkl_core.a -liomp5 -lpthread -lm -ldl

编译器选项:
 -m64 -I $ {MKLROOT} / include

我的目标是用CMake脚本编写此代码。我要去哪里了/要写这篇文章我必须写些什么?

cmake_minimum_required(VERSION 3.15)
project(PSD_Projections)

set(CMAKE_CXX_STANDARD 14)
set(MKL_DIR /opt/intel/mkl)

# Part for the linker line
# This seems to be somewhat okay
# However I can't figure out what to do about the other linker line arguments
find_library(LIB1 mkl_intel_lp64 ${MKL_DIR}/lib)
find_library(LIB2 mkl_intel_thread ${MKL_DIR}/lib)
find_library(LIB3 mkl_core ${MKL_DIR}/lib)
link_libraries(${LIB1} ${LIB2} ${LIB3})

# Part for the compiler options.
# ${MKL_DIR}/include is found and exists
# I don't know what to do about the -m64
include_directories(${MKL_DIR}/include)

add_executable(PSD_Projections main.cpp)

最佳答案

顺序ILP64版本的示例:

target_include_directories(PSD_Projections PUBLIC "${MKL_DIR}/include")
target_compile_definitions(PSD_Projections PUBLIC MKL_ILP64)
target_link_directories(PSD_Projections PUBLIC "${MKL_DIR}/lib/intel64")
target_link_libraries(PSD_Projections PUBLIC mkl_intel_ilp64 mkl_sequential mkl_core m dl)
target_link_options(PSD_Projections PUBLIC "-Wl,--no-as-needed")


可以轻松调整以适应您的需求。

如何设置C ++标准版本和编译器选项的示例:

target_compile_features(PSD_Projections PUBLIC cxx_std_14)
target_compile_options(PSD_Projections PUBLIC -Wall -Wpedantic -Wextra -m64 -march=native)

关于c++ - 链接库从命令行翻译到Make,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/58843333/

10-11 18:02