There was an error loading the library

Dear all,
I put the compiled dll file (written in C) in 'C:\Program Files\MATLAB\R2011b\extern\include\
I have a problem when I tried to load the library using the following command:
hfile = [matlabroot '\extern\include\dll\spinapi.h']; loadlibrary('spinapi', hfile)
it gave me the following error message:
Error using loadlibrary (line 421) There was an error loading the library "spinapi" The specified module could not be found.
Caused by: Error using loaddefinedlibrary The specified module could not be found.
My operating system is 64bit Win7, matlab is 64bit version, compiler is Microsoft Software Development Kit (SDK) 7.1, which is recommended in http://www.mathworks.com/support/compilers/R2011b/win64.html
Does anyone know what the problem is? I almost tried every method that I could find in google. But they didn't help. I am so deperated......
One thing made me very confused was that, I did exactly the same in my old computer, its operating system is 32bit Windows XP, matlab is R2009a 32bit version, compiler is lcc-win32 C, and it could load the library without any error!!!
I will be very thankful to anyone who can help me.
Best Regards, Kit

댓글 수: 1

Peter
Peter 2016년 1월 13일
Open your spinapi.dll in Dependency Walker (google: depends22_x64.zip). You will see which .dll files need to be copy or installed with your spinapi.dll

댓글을 달려면 로그인하십시오.

답변 (7개)

Philip Borghesani
Philip Borghesani 2012년 1월 12일

2 개 추천

I suggest using Dependency Walker to profile the loadlibrary call.
  1. Open .../bin/win64/matlab.exe with Dependency Walker.
  2. Start profiling
  3. Wait for MATLAB to come up and clear the log window
  4. Issue the loadlibrary command and examine the log in dDependency Walker for error messages.
The problem is probably a missing runtime library or other dll dependency.
Walter Roberson
Walter Roberson 2012년 1월 11일

0 개 추천

'C:\Program Files\MATLAB\R2011b\extern\include\' is not on my matlabpath, so I cannot think of any reason MATLAB would think to look there for .dll files. Did you add that directory to your matlabpath ?

댓글 수: 3

Kit Mai
Kit Mai 2012년 1월 11일
Hey Walter,
I did add that directory to my matlabpath.
Walter Roberson
Walter Roberson 2012년 1월 12일
Are you able to load the sample library using the form showed in "addpath example" in http://www.mathworks.com/help/techdoc/ref/loadlibrary.html ?
Kit Mai
Kit Mai 2012년 1월 12일
yes, I am able to load the 'Using alias Example' in http://www.mathworks.com/help/techdoc/ref/loadlibrary.html
any ideas?

댓글을 달려면 로그인하십시오.

Kit Mai
Kit Mai 2012년 1월 12일

0 개 추천

I tried the following command again, and it gave me a slightly different error message:
>> addpath(fullfile(matlabroot,'extern','include','dll'))
>> loadlibrary spinapi64 spinapi.h
Error using loadlibrary (line 421)
There was an error loading the library "C:\Program Files\MATLAB\R2011b\extern\include\dll\spinapi64.dll"
C:\Program Files\MATLAB\R2011b\extern\include\dll\spinapi64.dll is not a valid Win32 application.
Caused by: Error using loaddefinedlibrary
C:\Program Files\MATLAB\R2011b\extern\include\dll\spinapi64.dll is not a valid Win32 application.
What does it mean? Why is it looking for a valid Win32 application? Shouldn't it be 64bit?

댓글 수: 5

Walter Roberson
Walter Roberson 2012년 1월 12일
Hmmmm... I would wonder if you are really using the 64 bit version of MATLAB. Try giving the command
mexext
and see if it says mexw32 (32 bit MATLAB) or mexw64 (64 bit MATLAB)
Kit Mai
Kit Mai 2012년 1월 12일
God, it says mexw64!
Walter Roberson
Walter Roberson 2012년 1월 12일
Hmmm, I don't know; perhaps someone else will have an idea.
Mumble mumble... thunk file related ???
Kit Mai
Kit Mai 2012년 1월 12일
???
what do you mean?
Philip Borghesani
Philip Borghesani 2012년 1월 12일
Microsoft uses the same error messages for both 32 and 64 bit Windows. In their infinite wisdom they consider 64 bit programs to be written to the win32 api. There is no win64 api.

댓글을 달려면 로그인하십시오.

Kit Mai
Kit Mai 2012년 1월 12일

0 개 추천

by the way, the dll is coming from here: http://www.spincore.com/support/spinapi/SpinAPI_Main.shtml
The latest 64bit SpinAPI package.
64bit version of matlab is loading 64bit dll, but it does not work.......why?
Venugopal
Venugopal 2013년 4월 17일

0 개 추천

I have the similar problem of Kit Mai...
Kit Mai.. did u find some solution??
dpsycho
dpsycho 2013년 5월 21일

0 개 추천

Did you happen to have crashed before this happened?
I have the same thing. At some point everything worked, matlab crashed, and then could not load the library. Rebooted even and still no luck.
Muhammad
Muhammad 2024년 7월 2일

0 개 추천

tm3Proj = projcrs('ESRI:53008');
Did you find the solution?

카테고리

도움말 센터File Exchange에서 Search Path에 대해 자세히 알아보기

질문:

2012년 1월 11일

답변:

2024년 7월 2일

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by