Hi, recently I build a project using mkl through make, my simple CMakeLists is like this,
cmake_minimum_required(VERSION 3.14)
project(ex5 Fortran)
enable_language(Fortran)
find_package(MKL REQUIRED)
include_directories(${MKL_INCLUDE})
add_executable(ex5 main.f90)
target_link_libraries(ex5 ${MKL_LIBRARIES})
#target_link_options(ex5 PUBLIC $<LINK_ONLY:MKL::MKL>)
If I use target_link_libraries(ex5 ${MKL_LIBRARIES}), I can successfully build the project, but not for
#target_link_options(ex5 PUBLIC $<LINK_ONLY:MKL::MKL>), which shows this error,
ifort: error #10236: File not found: 'MKL::MKL'
could you help solve this?
链接已复制
Hi Meng,
cmake function target_link_options inserts the target as is, target_link_libraries should be used in order to resolve MKL target correctly.
Please refer to CMakeLists.txt from oneMKL Fortran examples for the correct way how to include oneMKL to CMake project for classic Fortran API:
<install_path>/oneapi/mkl/2021.4.0/examples/examples_core_f.tgz/f/CMakeLists.txt:
target_compile_options(${func} PUBLIC ${TEST_COPT} $<TARGET_PROPERTY:MKL::MKL,INTERFACE_COMPILE_OPTIONS>)
target_link_libraries(${func} PUBLIC ${TEST_LOPT} $<LINK_ONLY:MKL::MKL>)
This should fix it.
Khang