Intel® oneAPI Math Kernel Library
Ask questions and share information with other developers who use Intel® Math Kernel Library.

Linker error with gold

el_samuko
Beginner
1,042 Views

Hi there, when linking MKL with the GNU gold linker, the binaries seem to be broken:

#!/usr/bin/env bash

function cyan {
echo -e "\033[1;34m$*\033[0m"
}

MKL_DIR="$HOME/intel/oneapi/mkl/latest"
MKL_LIB_DIR="$MKL_DIR/lib/intel64"
MKL_INC_DIR="$MKL_DIR/include"

cat << EOF > demo.cpp
#include <iostream>
#include <string>
#include "mkl.h"
int main() {
std::string buffer(200, '\0');
MKL_Get_Version_String(buffer.data(), 200);
std::cout << buffer << std::endl;
}
EOF

COMPILER_ARGS="-I"$MKL_INC_DIR" demo.cpp -L"$MKL_LIB_DIR" -Wl,-rpath="$MKL_LIB_DIR" -lmkl_intel_ilp64 -lmkl_intel_thread -lmkl_core -liomp5"

cyan "Without gold:"
g++ $COMPILER_ARGS -o nogold
ldd nogold | grep mkl
./nogold

echo
cyan "With gold:"
g++ $COMPILER_ARGS -fuse-ld=gold -o withgold
ldd withgold | grep mkl
./withgold

echo
cyan "With mold:"
g++ $COMPILER_ARGS -fuse-ld=mold -o withmold
ldd withmold | grep mkl
./withmold

echo
cyan "Without gold, g++-12:"
g++-12 $COMPILER_ARGS -o nogold12
ldd nogold12 | grep mkl
./nogold12

echo
cyan "With gold, g++-12:"
g++-12 $COMPILER_ARGS -fuse-ld=gold -o withgold12
ldd withgold12 | grep mkl
./withgold12

echo
cyan "With mold, g++-12:"
g++-12 $COMPILER_ARGS -fuse-ld=mold -o withmold12
ldd withmold12 | grep mkl
./withmold12

The standard linker and mold do fine, but with gold I get:

With gold:
libmkl_intel_ilp64.so.2 => ~/intel/oneapi/mkl/latest/lib/intel64/libmkl_intel_ilp64.so.2 (0x00007f6b8daa3000)
./withgold: symbol lookup error: ~/intel/oneapi/mkl/latest/lib/intel64/libmkl_intel_ilp64.so.2: undefined symbol: mkl_blas_dgemm

This was tested with the latest MKL "2023.1-Product Build 20230303".

 

0 Kudos
1 Solution
VarshaS_Intel
Moderator
976 Views

Hi Samuel,

 

Thanks for posting in Intel Communities.

 

Could you please try using the below command where we are able to get the expected results using the option "-fuse-ld=gold":

 

 

 g++-12 -DMKL_ILP64 -m64 -I"${MKLROOT}/include" demoversion.cpp -o demogold12 -L${MKLROOT}/lib/intel64 -Wl,--no-as-needed -lmkl_intel_ilp64 -lmkl_gnu_thread -lmkl_core -lgomp -lpthread -lm -ldl -fuse-ld=gold

 

Please find the below screenshot where we have tried using the option -fuse-ld=gold and also without a gold linker.

VarshaS_Intel_0-1682594361096.png

And also, you can use the tool Intel Link Line Advisor for compiling and linking your code as it is compatible with several compilers and third-party libraries and provides different interfaces to the functionality. Please find the below link for more details:

https://www.intel.com/content/www/us/en/developer/tools/oneapi/onemkl-link-line-advisor.html

 

Could you please try and let us know if you face any errors?

 

Thanks & Regards,

Varsha

 

View solution in original post

5 Replies
VarshaS_Intel
Moderator
977 Views

Hi Samuel,

 

Thanks for posting in Intel Communities.

 

Could you please try using the below command where we are able to get the expected results using the option "-fuse-ld=gold":

 

 

 g++-12 -DMKL_ILP64 -m64 -I"${MKLROOT}/include" demoversion.cpp -o demogold12 -L${MKLROOT}/lib/intel64 -Wl,--no-as-needed -lmkl_intel_ilp64 -lmkl_gnu_thread -lmkl_core -lgomp -lpthread -lm -ldl -fuse-ld=gold

 

Please find the below screenshot where we have tried using the option -fuse-ld=gold and also without a gold linker.

VarshaS_Intel_0-1682594361096.png

And also, you can use the tool Intel Link Line Advisor for compiling and linking your code as it is compatible with several compilers and third-party libraries and provides different interfaces to the functionality. Please find the below link for more details:

https://www.intel.com/content/www/us/en/developer/tools/oneapi/onemkl-link-line-advisor.html

 

Could you please try and let us know if you face any errors?

 

Thanks & Regards,

Varsha

 

el_samuko
Beginner
966 Views

Hi Varsha,

 

thanks for your tipps. The -Wl,--no-as-needed before the libs was enough that ldd printed all libs and the programm could be executed successfully.

 

I got the command line for the compiler from the MKL included cmake:

find_package(MKL CONFIG REQUIRED)
target_link_libraries(demo MKL::MKL)

 

Regards,

Samuel

 

0 Kudos
VarshaS_Intel
Moderator
954 Views

Hi Samuel,


>>the programm could be executed successfully.

Glad to know that you are able to run without errors. Could you please confirm if we can close this case from our end?


Thanks & Regards,

Varsha


0 Kudos
el_samuko
Beginner
944 Views

Hi Varsha,

 

for me, yes.

I'd add the -Wl,--no-as-needed to cmake, though, as the link line advisor recommends.

 

Regards,

Samuel

0 Kudos
VarshaS_Intel
Moderator
935 Views

Hi Samuel,


>>for me, yes.

Thanks for the confirmation. Glad to know that your issue is resolved. If you need any additional information, please post a new question as this thread will

no longer be monitored by Intel.


Thanks & Regards,

Varsha


0 Kudos
Reply