error LNK2019: unresolved external symbol when trying to MEX a C++ file containing CUDA
7 次查看(过去 30 天)
显示 更早的评论
I’m trying to mex a C++ file that uses CUDA. I have included the folder containing cublas.h etc when calling mex and I’ve linked to the library in my CUDA toolbox folder.
mex -v NIPALS_gpu.cpp -I'C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v8.0\include' -L'C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v8.0\lib\x64'
but when I run it, it produces the error:
Error using mex
Creating library NIPALS_gpu.lib and object NIPALS_gpu.exp
NIPALS_gpu.obj : error LNK2019: unresolved external symbol cublasSetVector referenced in function "void __cdecl cublasSnormalize(int,int,float *,float
*,float *)" (?cublasSnormalize@@YAXHHPEAM00@Z)
….
And about 10 other similar LNK2019 errors.
Does anyone have experience in mexing CUDA and know what the error is about? Do I need to include some additional file that I’ve missed? The file I’m trying to mex ( NIPALS_gpu.cpp) is not something I’ve written, its available online and likely does not contain any errors.
0 个评论
回答(1 个)
Joss Knight
2016-10-3
mex on its own does not automatically link in the CUDA libraries, so you will have to do that manually using -lcublas or similar. Your -L switch has added a library path but hasn't actually added any libraries.
Easier still is to use the MEX wrapper mexcuda which both automatically links in the CUDA libraries, and links in the GPU mex interface so that you can pass MATLAB gpuArray objects into your mex function. (Obviously, this is only available with Parallel Computing Toolbox.)
2 个评论
Bob Khosh
2018-9-15
I do use "mexcuda" but i still get the following error:
Error using mex
Creating library mexMatrixMultiplication.lib and object
mexMatrixMultiplication.exp
mexMatrixMultiplication.obj : error LNK2019: unresolved
external symbol cublasCreate_v2 referenced in function
mexFunction
mexMatrixMultiplication.obj : error LNK2019: unresolved
external symbol cublasDestroy_v2 referenced in function
mexFunction
mexMatrixMultiplication.obj : error LNK2019: unresolved
external symbol cublasSetMatrix referenced in function
mexFunction
mexMatrixMultiplication.obj : error LNK2019: unresolved
external symbol cublasGetMatrix referenced in function
mexFunction
mexMatrixMultiplication.obj : error LNK2019: unresolved
external symbol cublasDgemm_v2 referenced in function
mexFunction
mexMatrixMultiplication.mexw64 : fatal error LNK1120: 5
unresolved externals
Error in mexcuda (line 157)
[varargout{1:nargout}] = mex(mexArguments{:});
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!