MATLAB: Error while loading library

loadlibraryMATLABshared library

I am trying to load a shared library from the sample code provided in the matlab documentation.
addpath(fullfile(matlabroot,'extern','examples','shrlib'))
if not(libisloaded('shrlibsample'))
loadlibrary('shrlibsample')
end
But when it tries to load the library i get an error:
Error using loadlibrary
The MATLAB program file describing your library could not be found, possible Perl or file system error.
Any help is appreciated.

Best Answer

I Finally found the solution for this problem. This was caused by a space/carriage return in the Path value of the Environment variable. It was not evident when I manually checked the path. Then i copied it to Notepad++ and found there was a space and a carriage return. Replaced the Path value with the edited path value(removing space and carriage return). Now the loadlibrary function works fine.
PS: The attached image has the markings about what i am talking about. The problem is only with WindowsPowershell\V1.0. Ignore the rest.