Error with using loadlibrary() with .lib file

6 views (last 30 days)
I'm trying to get MATLAB to load the library of an NI library file (.lib) named FlexMS32.lib. I downloaded the 32-bit MATLAB R2015b environment so it could interface with the file. However, when I try to load it, it returns this error:
Error using loaddefinedlibrary
...FlexMS32.lib is not a valid Win32 application.
I have no idea why it's returning this error. This is all the code I'm running:
loadlibrary('FlexMS32.lib', 'flexmotn.h', ...
'addheader', 'flexcomp.h', ...
'addheader', 'MotnCnst.h', ...
'addheader', 'MotnErr.h', ...
'addheader', 'nimcBasicTypes.h' ...
);

Answers (1)

Gyan Vaibhav
Gyan Vaibhav on 7 Mar 2024
Hi Mark,
If you could provide the lib file it would be easier for me to determine the error. However, looking at the error, I feel there are two possible reasons for this.
  1. Static libraries can't be loaded using loadlibrary. You have to convert it to a dll before using it. I've also read from another question's answer that one way to do this is to create a mex file that calls the function in the library.
  2. The error also suggests a possiblity that that a 64 bit operating system is trying to load a 32 bit Win32 file. Follow this answer to use the workaround. https://www.mathworks.com/matlabcentral/answers/99364-how-do-i-resolve-loadlibrary-failed-with-error-193-1-is-not-a-valid-win32-error-message-in-simul
Hope this helps.
Thanks
Gyan

Categories

Find more on MATLAB in Help Center and File Exchange

Products


Release

R2015b

Community Treasure Hunt

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

Start Hunting!