在macOS Sierra 10.12.3上运行使用英特尔Fortran编译器(15.0.3)和英特尔MKL编译的Fortran代码时遇到以下问题:
dyld: Library not loaded: libmkl_intel_lp64.dylib
Referenced from: /Users/username/tst_ddot/bin/./tst_ddot
Reason: image not found
Command terminated by signal 6
编译代码我使用cmake
(3.7.2)并运行代码make
(GNU 3.81,为i386-apple-darwin11.3.0构建)。
源代码:
PROGRAM tst_xdot
USE OMP_LIB
IMPLICIT NONE
integer, parameter :: N = 10
integer :: err
real, allocatable :: a(:), b(:)
real :: c1, c2
real :: t0, t1, time
real, external :: sdot
allocate(a(N), b(N), stat=err)
a = [1,2,3,4,5,6,7,8,9,10]
b = [10,9,8,7,6,5,4,3,2,1]
c1 = 0.0d+0
c2 = 0.0d+0
print *, "a:", a
print *, "b:", b
c1 = dot_product(a, b)
t0 = omp_get_wtime()
c2 = sdot(N, a, 1, b, 1)
t1 = omp_get_wtime()
time = t1-t0
print *, "c1:", c1
print *, "c2:", c2
print *, "time:", time
deallocate(a, b, stat=err)
END PROGRAM tst_xdot
CMakeLists.txt
档案:
# Minimum cmake version
cmake_minimum_required(VERSION 2.8.5)
# Project name
project(tst_ddot Fortran)
# set binary directory
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ../bin)
# Toolchain selection, possible arguments: Intel
set(Toolchain Intel)
# Intel compilers
if (${Toolchain} MATCHES Intel)
set(CMAKE_Fortran_FLAGS "-O3 ${CMAKE_Fortran_FLAGS}")
endif (${Toolchain} MATCHES Intel)
# Enable MKL library
include_directories($ENV{MKLROOT}/include)
link_directories($ENV{MKLROOT}/lib)
# Enable OpenMP
find_package(OpenMP)
if (OPENMP_FOUND)
set(CMAKE_Fortran_FLAGS "${CMAKE_Fortran_FLAGS} ${OpenMP_Fortran_FLAGS}")
endif()
# Source code files
set(SRC tst_ddot.f90)
# Main executable
add_executable(${PROJECT_NAME} ${SRC})
target_link_libraries(${PROJECT_NAME} ${LIBS} mkl_intel_lp64 mkl_intel_thread mkl_core pthread m)
只有在使用make文件运行代码时才会出现问题:
make run
制作文件来控制程序执行:
CODE = tst_ddot
run:
./$(CODE)
如果我直接从命令行运行代码:
./tst_ddot
程序正常执行。
答案 0 :(得分:0)
使用更新版本的GNU make
(GNU Make 4.2.1,为x86_64-apple-darwin16.4.0构建)可以解决这个问题。如果是MacPorts,它将被称为gmake
并默认安装到/opt/local/bin/gmake
。因此,运行代码的正确命令应为:
gmake run