0

I have the following problem. There is a need to install the mkl library (from there you need mainly lapack and blas to work with matrices and linear algebra). In fact, it does not matter that all this works in Visual Studio, if you can tell me where and how else, I will be grateful.

Actually, I downloaded the library from here: https://learn.microsoft.com/en-us/cognitive-toolkit/setup-mkl-on-windows and, it seems, I did all the necessary steps to install it: I added dll files to the project folder; in the project properties "C/C++ -> general -> Additional Include Directories" added the include folder from the installed archive; in "Linker -> general -> additional library directories" added the lib folder and in "Linker -> input -> additional dependencies" added 2 .lib files that were in the installed archive.

the following code:

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

int main()
{
    char transa = 'N';
    char transb = 'N';
    int n = 2;
    double alpha = 1.0;
    const double mat[4] = { 1, 2, 3, 2 };
    const double mat2[4] = { 2, 2, 2, 2 };
    double res[4] = {};
    DGEMM(&transa, &transb, &n, &n, &n, &alpha, mat, &n, mat2, &n, &alpha, res, &n);
    
    return 0;
}

returns the LNK2019 error: unresolved external symbol _DGEMM referenced in function _main. please tell me what I did wrong. If there is an option to do it somewhere not in VS, it also suits, because the functionality of the libraries is needed in the near future

Booch
  • 1
  • Likely duplicate: [What is an undefined reference/unresolved external symbol error and how do I fix it?](https://stackoverflow.com/questions/12573816/what-is-an-undefined-reference-unresolved-external-symbol-error-and-how-do-i-fix) – Jesper Juhl Nov 28 '22 at 06:18
  • From your description it sounds like you did everything right. – john Nov 28 '22 at 06:23
  • Maybe this is helpful https://community.intel.com/t5/Intel-oneAPI-Math-Kernel-Library/LNK2019-unresolved-external-symbol-DGEMM-referenced-in-function/td-p/1147959 – john Nov 28 '22 at 06:29
  • Two common pitfalls: Did you edit the right configuration (32/64 bit, Debug/Release) ? And are your paths right ? In VS they're relative to the *.vcxproj file, _not_ the *.sln. Try absolute paths for testing. – nick Nov 28 '22 at 06:30
  • Try using MKL Link line advisor and link MKL with microsoft visual studio. – Minxin Yu - MSFT Nov 28 '22 at 09:32
  • Any updates? Is the method in the answer useful? – Minxin Yu - MSFT Nov 30 '22 at 07:55
  • I haven't had time to try it yet. I will try on the weekend – Booch Nov 30 '22 at 08:51

1 Answers1

2

You can try it from the command prompt and the link line advisor https://www.intel.com/content/www/us/en/developer/tools/oneapi/onemkl-link-line-advisor.html?wapkw=link%20line%20advisor suggests you what are the required options that are needed in order to compile and link the code.

If you want to make it work in Visual Studio, I suggest you download oneAPI Base toolkit https://www.intel.com/content/www/us/en/developer/tools/oneapi/base-toolkit-download.html from where you can get the latest oneMKL.

During the installation of oneAPI Base toolkit it will automatically integrate the oneMKL to your VS 2019 thereby you just need to enable the /Qmkl option (unlike how you are adding the paths of header files and library files) in the configuration properties > Intel Libraries for oneAPI > use oneMKL (select the required option from the dropdown) and then build your code.

Here is a quick check from my end from the command prompt with the MSVC compiler and below is the command which has generated the .exe file successfully without any linking errors (here MKLROOT="C:\Program Files (x86)\Intel\oneAPI\mkl\2022.2.1\include")

CL test.cpp  -I"%MKLROOT%\include" /link /LIBPATH:"C:\Program Files (x86)\Intel\oneAPI\mkl\2022.2.1\lib\intel64" mkl_intel_lp64.lib mkl_sequential.lib mkl_core.lib