Search code examples
cgccintel-mkl

Compiling C code using Intel MKL: ld: unknown option: --no-as-needed


I wrote a C file (template.c) that uses the MKL Intel library (which I've already installed). I'm using this shell script to compile my code (template.c). Assume the C file is minimal - it imports the MKL library and has a main function - that's it.

source /opt/intel/compilers_and_libraries_2019.5.281/mac/mkl/bin/mklvars.sh intel64
gcc-9 -fopenmp -m64 -I${MKLROOT}/include -c template.c
gcc-9 -L${MKLROOT}/lib -Wl,--no-as-needed -lmkl_intel_lp64 -lmkl_gnu_thread -lmkl_core -lgomp -lpthread -lm -ldl template.o -o template
./template

However, I'm getting the following error on Mac (Intel 64-bit processor):

ld: unknown option: --no-as-needed

Any hints on why this may be happening? I'm using Homebrew's latest GCC version.

The first line of the script sources the environmental variables such as $MKLROOT which are used by the script. After that, it should create an object file and eventually run the executable called template.


Solution

  • Please be sure that you have used the recommended compiler options for the selected interface layer.

    Caution: linking Intel(R) MKL libraries with your objects compiled for different interface layer may lead to run-time errors.

    For reference go through the below link:

    Intel MKL Link Line Advisor https://software.intel.com/en-us/articles/intel-mkl-link-line-advisor