Intel® oneAPI Math Kernel Library
Ask questions and share information with other developers who use Intel® Math Kernel Library.
Announcements
The Intel sign-in experience is changing in February to support enhanced security controls. If you sign in, click here for more information.
6680 Discussions

An error occurs when linking mkl pardiso using cmake in linux.

Donghee
Beginner
322 Views

I am trying to compile a program that uses both the blas function and the pardiso function.

However, it works fine on Windows, but a link error occurs on Linux.

And if comment out pardiso in the code below, the link works fine, but if  use pardiso, a link error occurs.

It seems to work well when using only blas, so when using pardiso, there seems to be additional work to be done, but I have no idea what it is.

 

I am linking the static version library of mkl, and I am using Parallel Studio 2019 Update5 Cluster Edition.

 

Below is my code.

==========================================================

#include <iostream>
#include "mkl.h"

using namespace std;

void gmatgvec_mkl(const double a[], const double b[], const int m, const int n, double c[])
{
const double alpha = 1.0;
const double beta = 0.0;

if (m == 0 || n == 0) return;

cblas_dgemv(CblasColMajor, CblasNoTrans,
m, n, alpha, &a[0], m, &b[0], 1, beta, &c[0], 1);
}

int main(int argc, char* argv[])
{
cout << "Hello CMake. - project 1" << endl;

double matA[2 * 2];
double vecB[2];
double vecC[2];

matA[0] = 1.0;
matA[1] = 2.0;
matA[2] = 3.0;
matA[3] = 4.0;

vecB[0] = 5.0;
vecB[1] = 6.0;

gmatgvec_mkl(matA, vecB, 2, 2, vecC);

cout << "vecC[0] = " << vecC[0] << endl;
cout << "vecC[1] = " << vecC[1] << endl;

if (argc > 10) {
PARDISO(NULL, NULL, NULL,
NULL, NULL, NULL, NULL,
NULL, NULL, NULL, NULL,
NULL, NULL, NULL, NULL,
NULL);
}

return 0;
}

==========================================================

 

Below is my cmake file.

==========================================================

CMAKE_MINIMUM_REQUIRED (VERSION 2.8.12)

IF(NOT WIN32)
SET(CMAKE_C_COMPILER "$ENV{HOME}/intel/bin/icc")
SET(CMAKE_CXX_COMPILER "$ENV{HOME}/intel/bin/icpc")

SET(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -v")
SET(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -Wl,--no-undefined")
ENDIF()

PROJECT ("CMakeMKL")

IF(WIN32)
SET(MKL_INCLUDE "C:\\Program Files (x86)\\IntelSWTools\\compilers_and_libraries_2019.5.281\\windows\\mkl\\include")
SET(MKL_LIBRARY "C:\\Program Files (x86)\\IntelSWTools\\compilers_and_libraries_2019.5.281\\windows\\mkl\\lib\\intel64")
SET(ICPC_LIBRARY "C:\\Program Files (x86)\\IntelSWTools\\compilers_and_libraries_2019.5.281\\windows\\compiler\\lib\\intel64")
ELSE()
SET(MKL_INCLUDE "$ENV{HOME}/intel/mkl/include")
SET(MKL_LIBRARY "$ENV{HOME}/intel/mkl/lib/intel64")
SET(ICPC_LIBRARY "$ENV{HOME}/intel/lib/intel64")
ENDIF()

ADD_EXECUTABLE (${PROJECT_NAME}
CMakeProject1.cpp
)

TARGET_INCLUDE_DIRECTORIES(${PROJECT_NAME} PUBLIC
${MKL_INCLUDE}
)

IF(WIN32)
TARGET_LINK_LIBRARIES(${PROJECT_NAME} ${MKL_LIBRARY}\\mkl_intel_lp64.lib)
TARGET_LINK_LIBRARIES(${PROJECT_NAME} ${MKL_LIBRARY}\\mkl_intel_thread.lib)
TARGET_LINK_LIBRARIES(${PROJECT_NAME} ${MKL_LIBRARY}\\mkl_core.lib)
TARGET_LINK_LIBRARIES(${PROJECT_NAME} ${ICPC_LIBRARY}\\libiomp5md.lib)
ELSE()
#SET(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -Wl,-rpath=${MKL_LIBRARY}")
#SET(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -Wl,-rpath=${ICPC_LIBRARY}")
#SET(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -Wl,-rpath-link=${MKL_LIBRARY}")
#SET(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -Wl,-rpath-link=${ICPC_LIBRARY}")
#SET(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -Wl,--start-group ${MKL_LIBRARY}/libmkl_intel_lp64.a ${MKL_LIBRARY}/libmkl_intel_thread.a ${MKL_LIBRARY}/libmkl_core.a -Wl,--end-group -liomp5 -lpthread -lm -ldl")

TARGET_LINK_LIBRARIES(${PROJECT_NAME} ${MKL_LIBRARY}/libmkl_intel_lp64.a)
TARGET_LINK_LIBRARIES(${PROJECT_NAME} ${MKL_LIBRARY}/libmkl_intel_thread.a)
TARGET_LINK_LIBRARIES(${PROJECT_NAME} ${MKL_LIBRARY}/libmkl_core.a)
TARGET_LINK_LIBRARIES(${PROJECT_NAME} ${ICPC_LIBRARY}/libiomp5.a)

TARGET_LINK_LIBRARIES(${PROJECT_NAME} pthread)
TARGET_LINK_LIBRARIES(${PROJECT_NAME} dl)
TARGET_LINK_LIBRARIES(${PROJECT_NAME} m)
ENDIF()

===================================================

 

 

Below is the linker error message.

==========================================================

[1/2] Building CXX object CMakeFiles/CMakeMKL.dir/CMakeProject1.cpp.o
[2/2] Linking CXX executable CMakeMKL
FAILED: CMakeMKL
: && /home/dbae/intel/bin/icpc -g -v -Wl,--no-undefined -rdynamic CMakeFiles/CMakeMKL.dir/CMakeProject1.cpp.o -o CMakeMKL /home/dbae/intel/mkl/lib/intel64/libmkl_intel_lp64.a /home/dbae/intel/mkl/lib/intel64/libmkl_intel_thread.a /home/dbae/intel/mkl/lib/intel64/libmkl_core.a /home/dbae/intel/lib/intel64/libiomp5.a -lpthread -ldl -lm && :
icpc version 19.0.5.281 (gcc version 4.8.5 compatibility)
/home/dbae/intel/compilers_and_libraries_2019.5.281/linux/bin/intel64/mcpcom -mGLOB_em64t=TRUE -mP1OPT_version=19.0-intel64 -mGLOB_diag_file=CMakeFiles/CMakeMKL.dir/CMakeProject1.cpp.diag -mGLOB_long_size_64 -mGLOB_routine_pointer_size_64 -mP1OPT_print_version=FALSE -mCG_use_gas_got_workaround=F -mP2OPT_align_option_used=TRUE -mGLOB_gcc_version=485 "-mGLOB_options_string=-g -v -Wl,--no-undefined -rdynamic -o CMakeMKL -lpthread -ldl -lm" -mGLOB_cxx_limited_range=FALSE -mCG_extend_parms=FALSE -mGLOB_compiler_bin_directory=/home/dbae/intel/compilers_and_libraries_2019.5.281/linux/bin/intel64 -mP3OPT_emit_line_numbers -mGLOB_debug_target=GLOB_DEBUG_TARGET_ALL -mDEBUG_info_level=2 -mDEBUG_use_indirect_strings=TRUE -mIPOPT_ninl_debug_info=TRUE -mDEBUG_emit_dwarf_inline_info=TRUE -mDEBUG_debug_ranges=TRUE -mGLOB_debug_format=GLOB_DEBUG_FORMAT_DWARF40 -mGLOB_as_output_backup_file_name=/tmp/icpcGA3opZas_.s -mGLOB_dashboard_use_source_name -mIPOPT_activate -mGLOB_product_id_code=0x22006d90 -mP3OPT_use_mspp_call_convention -mP2OPT_subs_out_of_bound=FALSE -mP2OPT_disam_type_based_disam=2 -mP2OPT_disam_assume_ansi_c -mP2OPT_checked_disam_ansi_alias=TRUE -mGLOB_ansi_alias -mPGOPTI_value_profile_use=T -mGLOB_opt_report_use_source_name -mP2OPT_il0_array_sections=TRUE -mGLOB_offload_mode=1 -mP2OPT_offload_unique_var_string=icpc0174938581JqCV9F -mP2OPT_hlo -mP2OPT_hpo_rtt_control=0 -mIPOPT_args_in_regs=0 -mP2OPT_disam_assume_nonstd_intent_in=FALSE -mGLOB_imf_mapping_library=/home/dbae/intel/compilers_and_libraries_2019.5.281/linux/bin/intel64/libiml_attr.so -mP2OPT_hlo_embed_loopinfo -mPGOPTI_gen_threadsafe_level=0 -mIPOPT_link -mIPOPT_ipo_activate -mIPOPT_mo_activate -mIPOPT_source_files_list=/tmp/icpcslisxQwR0s -mIPOPT_mo_global_data -mIPOPT_link_script_file=/tmp/icpcscriptuZD6ce "-mIPOPT_cmdline_link="/usr/lib/gcc/x86_64-redhat-linux/4.8.5/../../../../lib64/crt1.o" "/usr/lib/gcc/x86_64-redhat-linux/4.8.5/../../../../lib64/crti.o" "/usr/lib/gcc/x86_64-redhat-linux/4.8.5/crtbegin.o" "-export-dynamic" "--eh-frame-hdr" "--build-id" "-dynamic-linker" "/lib64/ld-linux-x86-64.so.2" "-m" "elf_x86_64" "-o" "CMakeMKL" "-L/home/dbae/intel/compilers_and_libraries_2019.5.281/linux/compiler/lib/intel64_lin" "-L/usr/lib/gcc/x86_64-redhat-linux/4.8.5/" "-L/usr/lib/gcc/x86_64-redhat-linux/4.8.5/../../../../lib64" "-L/usr/lib/gcc/x86_64-redhat-linux/4.8.5/../../../../lib64/" "-L/lib/../lib64" "-L/lib/../lib64/" "-L/usr/lib/../lib64" "-L/usr/lib/../lib64/" "-L/usr/lib/gcc/x86_64-redhat-linux/4.8.5/../../../" "-L/lib64" "-L/lib/" "-L/usr/lib64" "-L/usr/lib" "--no-undefined" "CMakeFiles/CMakeMKL.dir/CMakeProject1.cpp.o" "/home/dbae/intel/mkl/lib/intel64/libmkl_intel_lp64.a" "/home/dbae/intel/mkl/lib/intel64/libmkl_intel_thread.a" "/home/dbae/intel/mkl/lib/intel64/libmkl_core.a" "/home/dbae/intel/lib/intel64/libiomp5.a" "-lpthread" "-ldl" "-L/home/dbae/intel/compilers_and_libraries_2019.5.281/linux/compiler/lib/intel64_lin" "-Bstatic" "-limf" "-Bdynamic" "-lm" "-Bdynamic" "-Bstatic" "-limf" "-lsvml" "-lirng" "-Bdynamic" "-lstdc++" "-lm" "-Bstatic" "-lipgo" "-ldecimal" "--as-needed" "-Bdynamic" "-lcilkrts" "--no-as-needed" "-lstdc++" "-lgcc" "-lgcc_s" "-Bstatic" "-lirc" "-lsvml" "-Bdynamic" "-lc" "-lgcc" "-lgcc_s" "-Bstatic" "-lirc_s" "-Bdynamic" "-ldl" "-lc" "/usr/lib/gcc/x86_64-redhat-linux/4.8.5/crtend.o" "/usr/lib/gcc/x86_64-redhat-linux/4.8.5/../../../../lib64/crtn.o"" -mIPOPT_il_in_obj -mIPOPT_ipo_activate_warn=FALSE -mIPOPT_obj_output_file_name=/tmp/ipo_icpcrAJlQT.o -mIPOPT_whole_archive_fixup_file_name=/tmp/icpcwarchn1fqPv -mGLOB_linker_version=2.27 -mGLOB_linker=ld -mGLOB_driver_tempfile_name=/tmp/icpctempfileuXX82g -mP3OPT_asm_target=P3OPT_ASM_TARGET_GAS -mGLOB_async_unwind_tables=TRUE -mGLOB_obj_output_file=/tmp/ipo_icpcrAJlQT.o -mGLOB_source_dialect=GLOB_SOURCE_DIALECT_NONE -mP1OPT_source_file_name=ipo_out.c CMakeFiles/CMakeMKL.dir/CMakeProject1.cpp.o -mIPOPT_object_files=T -mIPOPT_assembly_files=/tmp/icpcalisUlmkeq -mIPOPT_generated_tempfiles=/tmp/icpcelisNDkoqb -mIPOPT_embedded_object_base_name=/tmp/icpceobj8tcvCW -mIPOPT_cmdline_link_new_name=/tmp/icpcllispX7EOH
ld /usr/lib/gcc/x86_64-redhat-linux/4.8.5/../../../../lib64/crt1.o /usr/lib/gcc/x86_64-redhat-linux/4.8.5/../../../../lib64/crti.o /usr/lib/gcc/x86_64-redhat-linux/4.8.5/crtbegin.o -export-dynamic --eh-frame-hdr --build-id -dynamic-linker /lib64/ld-linux-x86-64.so.2 -m elf_x86_64 -o CMakeMKL -L/home/dbae/intel/compilers_and_libraries_2019.5.281/linux/compiler/lib/intel64_lin -L/usr/lib/gcc/x86_64-redhat-linux/4.8.5/ -L/usr/lib/gcc/x86_64-redhat-linux/4.8.5/../../../../lib64 -L/usr/lib/gcc/x86_64-redhat-linux/4.8.5/../../../../lib64/ -L/lib/../lib64 -L/lib/../lib64/ -L/usr/lib/../lib64 -L/usr/lib/../lib64/ -L/usr/lib/gcc/x86_64-redhat-linux/4.8.5/../../../ -L/lib64 -L/lib/ -L/usr/lib64 -L/usr/lib --no-undefined CMakeFiles/CMakeMKL.dir/CMakeProject1.cpp.o /home/dbae/intel/mkl/lib/intel64/libmkl_intel_lp64.a /home/dbae/intel/mkl/lib/intel64/libmkl_intel_thread.a /home/dbae/intel/mkl/lib/intel64/libmkl_core.a /home/dbae/intel/lib/intel64/libiomp5.a -lpthread -ldl -L/home/dbae/intel/compilers_and_libraries_2019.5.281/linux/compiler/lib/intel64_lin -Bstatic -limf -Bdynamic -lm -Bdynamic -Bstatic -limf -lsvml -lirng -Bdynamic -lstdc++ -lm -Bstatic -lipgo -ldecimal --as-needed -Bdynamic -lcilkrts --no-as-needed -lstdc++ -lgcc -lgcc_s -Bstatic -lirc -lsvml -Bdynamic -lc -lgcc -lgcc_s -Bstatic -lirc_s -Bdynamic -ldl -lc /usr/lib/gcc/x86_64-redhat-linux/4.8.5/crtend.o /usr/lib/gcc/x86_64-redhat-linux/4.8.5/../../../../lib64/crtn.o
/home/dbae/intel/mkl/lib/intel64/libmkl_core.a(pardiso_lp64.o): In function `mkl_pds_lp64_pardiso':
pardiso_lp64_h.f:(.text+0x18a): undefined reference to `mkl_pds_lp64_pds_get_omp_num_threads'
pardiso_lp64_h.f:(.text+0x198): undefined reference to `mkl_pds_lp64_pds_get_num_threads'
pardiso_lp64_h.f:(.text+0x1a4): undefined reference to `mkl_pds_lp64_pds_get_omp_num_threads'
pardiso_lp64_h.f:(.text+0x1b0): undefined reference to `mkl_pds_lp64_pds_get_num_threads'
pardiso_lp64_h.f:(.text+0x31b): undefined reference to `mkl_pds_lp64_get_dynamic_pardiso'
pardiso_lp64_h.f:(.text+0x351): undefined reference to `mkl_pds_lp64_pardiso_max_threads'
/home/dbae/intel/mkl/lib/intel64/libmkl_core.a(pds_pardiso_lp64.o): In function `mkl_pds_lp64_dist_pardiso':
pds_pardiso.c:(.text+0x828): undefined reference to `mkl_pds_lp64_pds_refinement_real'
pds_pardiso.c:(.text+0x8ed): undefined reference to `mkl_pds_lp64_pds_refinement_cmplx'
/home/dbae/intel/mkl/lib/intel64/libmkl_core.a(pds_factorization_lp64.o): In function `mkl_pds_lp64_pds_factorization':
pds_factorization.c:(.text+0x25): undefined reference to `mkl_pds_lp64_pds_copy_a2l_value_omp_cmplx'
pds_factorization.c:(.text+0x2f): undefined reference to `mkl_pds_lp64_pds_copy_a2l_value_omp_real'
pds_factorization.c:(.text+0x86): undefined reference to `mkl_pds_lp64_pds_fct_omp_driver_cmplx'
pds_factorization.c:(.text+0x95): undefined reference to `mkl_pds_lp64_pds_fct_omp_driver_real'
/home/dbae/intel/mkl/lib/intel64/libmkl_core.a(pardiso_c_lp64.o): In function `mkl_pds_lp64_pardiso_c':
pardiso_c.c:(.text+0x8df9): undefined reference to `mkl_pds_lp64_convert_to_vbsr'
/home/dbae/intel/mkl/lib/intel64/libmkl_core.a(kernel_dispatch_lp64.o): In function `mkl_pds_lp64_kernel_dispatch':
kernel_dispatch.c:(.text+0x2ff): undefined reference to `mkl_pds_lp64_pds_slv_nrhs_seq_real'
kernel_dispatch.c:(.text+0x37f): undefined reference to `mkl_pds_lp64_pds_slv_nrhs_par_real'
kernel_dispatch.c:(.text+0x408): undefined reference to `mkl_pds_lp64_pds_slv_nrhs_seq_cmplx'
kernel_dispatch.c:(.text+0x485): undefined reference to `mkl_pds_lp64_pds_slv_nrhs_par_cmplx'
kernel_dispatch.c:(.text+0x57c): undefined reference to `mkl_pds_lp64_iter_ref_seq_nrhs_real'
kernel_dispatch.c:(.text+0x5fa): undefined reference to `mkl_pds_lp64_iter_ref_par_nrhs_real'
kernel_dispatch.c:(.text+0x692): undefined reference to `mkl_pds_lp64_iter_ref_seq_nrhs_cmplx'
kernel_dispatch.c:(.text+0x70d): undefined reference to `mkl_pds_lp64_iter_ref_par_nrhs_cmplx'
kernel_dispatch.c:(.text+0x80d): undefined reference to `mkl_pds_lp64_pds_sym_indef_diag_fct_slv_seq_cmplx'
kernel_dispatch.c:(.text+0x8ad): undefined reference to `mkl_pds_lp64_pds_sym_indef_bk_fct_slv_seq_cmplx'
kernel_dispatch.c:(.text+0x95b): undefined reference to `mkl_pds_lp64_pds_sym_indef_diag_fct_slv_cmplx'
kernel_dispatch.c:(.text+0x9fb): undefined reference to `mkl_pds_lp64_pds_sym_indef_bk_fct_slv_cmplx'
kernel_dispatch.c:(.text+0xaa8): undefined reference to `mkl_pds_lp64_pds_her_pos_fct_slv_seq_cmplx'
kernel_dispatch.c:(.text+0xb48): undefined reference to `mkl_pds_lp64_pds_her_pos_fct_slv_cmplx'
kernel_dispatch.c:(.text+0xc09): undefined reference to `mkl_pds_lp64_pds_unsym_fct_slv_seq_cmplx'
kernel_dispatch.c:(.text+0xcbd): undefined reference to `mkl_pds_lp64_pds_unsym_fct_slv_cmplx'
kernel_dispatch.c:(.text+0xd60): undefined reference to `mkl_pds_lp64_pds_sym_pos_fct_slv_seq_real'
kernel_dispatch.c:(.text+0xdf6): undefined reference to `mkl_pds_lp64_pds_sym_pos_fct_slv_real'
kernel_dispatch.c:(.text+0xea2): undefined reference to `mkl_pds_lp64_pds_unsym_fct_slv_seq_real'
kernel_dispatch.c:(.text+0xf38): undefined reference to `mkl_pds_lp64_pds_unsym_fct_slv_t_seq_real'
kernel_dispatch.c:(.text+0xfd7): undefined reference to `mkl_pds_lp64_pds_unsym_fct_slv_real'
kernel_dispatch.c:(.text+0x106d): undefined reference to `mkl_pds_lp64_pds_unsym_fct_slv_t_real'
kernel_dispatch.c:(.text+0x111e): undefined reference to `mkl_pds_lp64_pds_sym_indef_diag_fct_slv_seq_real'

.

.

.

.

 

==========================================================

 

 

No matter how much I google it, it doesn't fix it. please help me please!

0 Kudos
1 Solution
VidyalathaB_Intel
Moderator
307 Views

Hi,

 

Thanks for reaching out to us.

>>but a link error occurs on Linux.

I could reproduce the issue from my end with the provided CMake file.

Since the issue comes during the linking stage, I tried modifying your CMakeLists.txt at the target_link_libraries command as shown below (you can comment out the remaining target_link_libraries commands (for Linux) and just insert this single line.

 

TARGET_LINK_LIBRARIES(${PROJECT_NAME} "-Wl,--start-group" ${MKL_LIBRARY}/libmkl_intel_lp64.a ${MKL_LIBRARY}/libmkl_intel_thread.a ${MKL_LIBRARY}/libmkl_core.a "-Wl,--end-group -liomp5 -lpthread -lm -ldl")

 

After the above change, it works successfully. I don't see the linking errors which we saw before.

Here is the output :

VidyalathaB_Intel_0-1651738965910.png

 

Please try it and let me know if you still face any issues.

 

Regards,

Vidya.

 

View solution in original post

3 Replies
VidyalathaB_Intel
Moderator
308 Views

Hi,

 

Thanks for reaching out to us.

>>but a link error occurs on Linux.

I could reproduce the issue from my end with the provided CMake file.

Since the issue comes during the linking stage, I tried modifying your CMakeLists.txt at the target_link_libraries command as shown below (you can comment out the remaining target_link_libraries commands (for Linux) and just insert this single line.

 

TARGET_LINK_LIBRARIES(${PROJECT_NAME} "-Wl,--start-group" ${MKL_LIBRARY}/libmkl_intel_lp64.a ${MKL_LIBRARY}/libmkl_intel_thread.a ${MKL_LIBRARY}/libmkl_core.a "-Wl,--end-group -liomp5 -lpthread -lm -ldl")

 

After the above change, it works successfully. I don't see the linking errors which we saw before.

Here is the output :

VidyalathaB_Intel_0-1651738965910.png

 

Please try it and let me know if you still face any issues.

 

Regards,

Vidya.

 

Donghee
Beginner
269 Views

Thank you so much Vidya!

I'm very happy that the problem that has been going on for several weeks has been resolved!

VidyalathaB_Intel
Moderator
265 Views

Hi,


Thanks for accepting our solution and glad to know that it worked.

As the issue is resolved we are closing this thread. Please post a new question if you need any additional assistance from Intel as this thread will no longer be monitored.


Have a Great Day!


Regards,

Vidya.


Reply