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

Difficulty using MKL in VSCode

F_L
Beginner
1,333 Views

Hello,

I'm encountering an issue while trying to use Intel Math Kernel Library (MKL) in my C++ project within Visual Studio Code (VSCode).

I have successfully installed Base Toolkit on my windows system, and I'm using the "C/C++ IntelliSense, debugging, and code browsing" extension for VSCode.

The mkl_example.cpp is given below:

 

#include <Rcpp.h>
#include <mkl.h>
using namespace Rcpp;
// Define the example function
// [[Rcpp::export]]
List example(Rcpp::NumericVector para) {
  int n = para.size();
  NumericVector result(n); 
  // Get a pointer to the data of the NumericVector
  const double* para_ptr = para.begin();
  // Perform the element-wise addition
  vdAdd(n, para_ptr, para_ptr, result.begin());
  return List::create(_["result"] = result);
}

 

The "c_cpp_properties.json" file contains the following:

 

{
    "configurations": [
        {
            "name": "Win32",
            "includePath": [
                "${workspaceFolder}/**",
                "C:/Users/user/AppData/Local/R/win-library/4.3/Rcpp/include",
                "C:/PROGRA~1/R/R-43~1.1/include",
                "C:/Program Files (x86)/Intel/oneAPI/mkl/latest/include"
            ],
            "defines": [
                "_DEBUG",
                "UNICODE",
                "_UNICODE"
            ],
            "compilerPath": "C:\\mingw64\\bin\\gcc.exe",
            "cStandard": "c17",
            "cppStandard": "gnu++14",
            "intelliSenseMode": "windows-gcc-x64"
        }
    ],
    "version": 4
}

 

 

I run the following commands: 

 

 

library(Rcpp)
cpp_file <- "C:/Users/user/OneDrive/Documents/VariousCodes/mkl/mkl_example.cpp"
sourceCpp(cpp_file)
# Create a numeric vector
input_vector <- c(1, 2, 3, 4, 5)
# Call the C++ function
result <- example(input_vector)
# 'result' now contains the element-wise addition of 'input_vector'

 

 

and get the flowing output:

 

 

> source("c:\\Users\\user\\OneDrive\\Documents\\VariousCodes\\$
using C++ compiler: 'G__~1.EXE (GCC) 12.2.0'
g++ -std=gnu++17  -I"C:/PROGRA~1/R/R-43~1.1/include" -DNDEBUG   -I"C:/Users/user/AppData/Local/R/win-library/4.3/Rcpp/include" -I"C:/Users/user/OneDrive/Documents/VariousCodes/mkl"   -I"C:/rtools43/x86_64-w64-mingw32.static.posix/include"     -O2 -Wall  -mfpmath=sse -msse2 -mstackrealign  -c mkl.cpp -o mkl.o
g++ -std=gnu++17 -shared -s -static-libgcc -o sourceCpp_2.dll tmp.def mkl.o -LC:/rtools43/x86_64-w64-mingw32.static.posix/lib/x64 -LC:/rtools43/x86_64-w64-mingw32.static.posix/lib -LC:/PROGRA~1/R/R-43~1.1/bin/x64 -lR
C:\rtools43\x86_64-w64-mingw32.static.posix\bin/ld.exe: mkl.o:mkl.cpp:(.text+0x3ea): undefined reference to `vdAdd'
collect2.exe: error: ld returned 1 exit status
Error in sourceCpp(cpp_file) : Error occurred building shared library.

 

 

I think that i have included the directory for the Intel oneAPI Math Kernel Library (MKL). In the system environment variables, you have added the following entries to the "Path."

 

 

C:\Program Files (x86)\Intel\oneAPI\compiler\latest\windows\compiler\lib\intel64
C:\Program Files (x86)\Intel\oneAPI\compiler\latest\windows\compiler\lib\intel64_win
C:\Program Files (x86)\Intel\oneAPI\compiler\latest\windows\compiler\lib\ia32
C:\Program Files (x86)\Intel\oneAPI\compiler\latest\windows\compiler\lib\ia32_win
C:\Program Files (x86)\Intel\oneAPI\tbb\latest\redist\intel64\vc_mt\
C:\Program Files (x86)\Intel\oneAPI\tbb\latest\redist\ia32\vc_mt\
C:\Program Files (x86)\Intel\oneAPI\compiler\latest\windows\redist\intel64_win\compiler
C:\Program Files (x86)\Intel\oneAPI\compiler\latest\windows\redist\ia32_win\compiler
C:\Program Files (x86)\Intel\oneAPI\compiler\2023.2.1\windows\bin

 

 

I would appreciate any help.

FL

0 Kudos
1 Reply
JilaniS_Intel
Employee
1,241 Views

Hi Fio,


Thanks for posting in Intel communities.

 

We regret to say that we will not be able to support you on this R related query. We are not “R” experts. 


If you have any query on Intel products, then please raise a new thread in the appropriate forum and we’d be happy to support you. Thank you.


 

Regards,

Jilani


0 Kudos
Reply