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

MKL program compiled with Visual Studio 2022 cannot be executed at the command prompt

Kaoreen
Beginner
270 Views

Hello,

I got the oneMKL stand-alone version from Intel® oneAPI Math Kernel Library (oneMKL)   and wrote a Windows console application. It works fine from within Visual Studio 2022 and the oneAPI command prompt for Intel64 in Visual Studio 2022.
However, when I tried to run it from the Windows command prompt, it said "mkl_intel_thread.2.dll not found". So I copied the dll to the folder with the .exe file and ran it, there is no error but it just printed "Hello World!".

Here is my program.

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

using namespace std;

#define N 2

int main()
{
	std::cout << "Hello World!" << std::endl;

	// 5x + 3y = 9
	// 2x +  y = -1
	double A[N * N], b[N];
	A[0] = 5; A[2] = 3;
	A[1] = 2; A[3] = 1;
	b[0] = 9;
	b[1] = 4;

	int n = N;
	int ipiv = N;
	int lda = N, ldb = N, info;
	dgetrf(&n, &n, A, &lda, &ipiv, &info);

	int nrhs = 1;
	const char trans = 'N';
	dgetrs_(&trans, &n, &nrhs, A, &lda, &ipiv, b, &ldb, &info);

	std::cout << "x = " << b[0] << std::endl;
	std::cout << "y = " << b[1] << std::endl;
	return 0;
}

And project properties I set.

  1. Intel Libraries for oneAPI > Intel oneAPI Math Kernel Library(oneMKL)
    Use oneMKL > Parallel
    Use ILP64 interfaces > No
    Use MPI Library > Intel MPI Library
  2. VC++ Directories
    Include Directories > C:\Program Files (x86)\Intel\oneAPI\mkl\2024.1\include;
    C:\Program Files (x86)\Intel\oneAPI\mkl\2024.1\include\mkl\intel64
    Library Directories > C:\Program Files (x86)\Intel\oneAPI\compiler\latest\lib
    Executable Directories > C:\Program Files (x86)\Intel\oneAPI\compiler\2024.1\bin

My question is:

How do I compile this code in Visual Studio so that I can run the .exe file in the Windows Command Prompt?


Many thanks,

 

 

0 Kudos
2 Replies
Mark_L_Intel
Moderator
173 Views

Hello @Kaoreen,

  The message about “mkl_intel_thread.2.dll not found” indicates that the dynamic link library (DLL) required by oneMKL wasn’t found in the system path.

   Copying the DLL to the same folder as your executable is a good temporary fix, but to ensure that all necessary oneMKL DLLs are available, it’s better to add the directory containing the MKL DLLs to your system’s PATH environment variable. This way, any program that requires these DLLs can find them without having to copy them into the same directory.  Please try it. It may fix your other issues too.  

 

0 Kudos
Kaoreen
Beginner
159 Views

Thanks for letting me know the solution.

I set "C:\Program Files (x86)\Intel\oneAPI\mkl\2024.1\bin" in the system PATH and removed "mkl_intel_thread.2.dll" from the folder containing the .exe.

The program can now be run in Windows cmd.
Thanks a lot.


In fact, this is very simple, but I couldn't notice it because I don't get any errors in Windows cmd.
You can close this thread now.

Thanks again.

Best regards.

0 Kudos
Reply