loadlibrary - Matlab R2013b 64bit

4 views (last 30 days)
Hello,
I have been trying to load a 64-bit library (.dll) using the command "loadlibrary" on Matlab 64-bit, but I always receive the following error:
Error using loadlibrary (line 418) C:\Users\****\AppData\Local\Temp\tpe7fb8e10_222c_47c3_ad59_ab00161c9411\shrlibsample_thunk_pcwin64.dll is not a valid Win32 application.
As you may see, the library I am attempting to load is the shrlibsample, using the following commands:
>> addpath(fullfile(matlabroot,'extern','examples','shrlib')) >> loadlibrary('shrlibsample','shrlibsample.h')
And I also have Microsoft Software Development Kit (SDK) 7.1 set as compiler for Matlab (mbuild -setup).
I have already read several questions related to this issue, but I did not find any similar to the problem I am facing: I am trying to load a 64-bit library on a 64-bit Matlab and the error reported by the latter is related to an expectation of loading a 32-bit library, what does not make sense to me.
Some additional info: I also have Matlab 32-bit installed on my computer (Win7 64-bit), which also makes use of SDK 7.1 as compiler and I am able to load any (32-bit) library on that Matlab.
Any ideas or suggestions are very much appreciated.
Thanks, Guilherme

Accepted Answer

Philip Borghesani
Philip Borghesani on 1 Dec 2014
Edited: Philip Borghesani on 1 Dec 2014
Contacting support may be your best option for this problem. Something is most likely not configured or installed correctly with your compiler.
All 64bit and 32bit windows programs & dlls are considered to be win32 applications this is a Microsoft oddity (system32 contains all 64bit programs...). The error message does not necessarily indicate improper program type or confusion, just that it could not be loaded.
I would start by adding mfilename option to your loadlibrary command and then running Dependency Walker on the generated thunk dll to see if you can figure out what is wrong with it.
Does the mex command work correctly for you? Can you build and run an example mex file? What version of Matlab are you running the way loadlibrary builds the thunk files has changed in recent versions.
  2 Comments
Guilherme
Guilherme on 1 Dec 2014
Hi Philip,
Thanks for the prompt [and very precise] reply!
I have just tried to build a mex-file and I've got an error regarding the file mexopts.bat: "You cannot use this file with the WIN64 architecture because it enables a compiler for a different architecture."
Matlab suggested to run "mex -setup" in order to fix that. I was asked to select the compiler for the mex option and I chose the SDK 7.1 (same as for mbuild).
After doing that, I was able to run both mex and loadlibrary correctly.
Thanks again!
Philip Borghesani
Philip Borghesani on 2 Dec 2014
I should have noticed you also have 32bit MATLAB installed. One of the problems with this configuration is that mex -setup saves the setup to a file that is used by both 32 and 64 bit MATLAB but will only work correctly with the MATLAB it is created with.

Sign in to comment.

More Answers (0)

Categories

Find more on Troubleshooting in MATLAB Compiler SDK in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!