Problem trying to load .dll library using 'loadlibrary', error is, A 'Selected' compiler was not found. You may need to run mex -setup.

I am a beginner on using the loadlibrary function and using .dll files, so I will appreciate any help I can get.
I am trying to load a .dll file with a header file, I am using:
>> loadlibrary('nameoflibrarydll', 'nameofheaderfile')
and it comes up with the error:
??? Error using ==> loadlibrary at 264 A 'Selected' compiler was not found. You may need to run mex -setup.
I do not understand what 'mex' is?
I think a problem is is that the .dll file is written using an old version of Matlab, and it needs to be used using Matlab 2011a. This is so that I can access functions from the header file, the codes of which probably need updating also to run in the new version of Matlab.
I also tried the same line of code for loadlibrary on a different computer and it comes up with the error:
C:\Users\User One\Documents\MATLAB Pentools\Wintab32.dll is not a valid Win32 application.
I understand the problem is to do with 32 bit and 64 bit versions of windows, but I do not understand what this means. If anyone could help explain what all the terminology means and how you think I may be able to proceed with accessing the .dll file, I would be most grateful.

 Réponse acceptée

Hi,
in order to use loadlibrary you need to choose a compiler. In order to choose a compiler run
mex -setup
This starts a small setup routine in which you select your compiler.
In addition, 32bit ML can load 32bit DLLs only. 64bit ML can load 64bit DLLs only.
How was the DLL generated? I hope not with the MATLAB Compiler, because you shouldn't/can't load ML Compiler generated DLLs in MATLAB. They are not designed to work with loadlibrary and will most likely crash ML.

6 commentaires

I have used the 'mex-setup' function and selected an option for visual c++ option, however it then came up with the error:
??? Undefined function or variable 'setup'.
after I had chosen which compiler to use.
I then ran the 'mex-setup' command again and got the following output:
>> mex-setup
Usage:
MEX [option1 ... optionN] sourcefile1 [... sourcefileN]
[objectfile1 ... objectfileN] [libraryfile1 ... libraryfileN]
Use the -help option for more information, or consult the MATLAB API Guide.
Y:\MA2051~1\BIN\MEX.PL: Error: No file names given.
??? Undefined function or variable 'setup'.
Would you be able to explain what you mean by 'ML'? I really am a beginner with the terminology.
I am not sure how the dll was generated. I just have a file name with the extension .dll that I am trying to access with the header file.
Hi,
ML means MATLAB. Please put a space between mex and -setup, simply copy & paste the command from post into ML.
In addition, ML can pass C header files only. So please make sure you header file is native C code (so no C++ syntax).
For limitations and workarounds see here:
http://www.mathworks.com/help/techdoc/matlab_external/f43202.html#bruzh57-1
Yeah, I realised I had missed the space out, thanks.
I think the header file is in C, need to check on that.
Would you be able to say what language the .dll file should be in? I cannot view its contents, just jumbled up symbols.
I now get the error message:
??? Error using ==> loadlibrary at 441
There was an error loading the library
Caused by: Error using ==> loaddefinedlibrary not a valid Win32 application.
I am using a 32-bit operating system, so do not understand this error message in context? In the header file there is a comment line at the start stating that it is a combined 16 and 32 bit version. I thought maybe the 16-bit parts could be causing the problem? If those lines of code in 16-bit were identified and edited to be 32-bit, would that make any sense?
Thanks again!
It doesnt matter if the DLL is written in C or C++.
I never saw such a 16/32bit DLL. Not sure if MATLAB can handle this. But this message can also mean that the DLL is a 64bit DLL, since the header talks about 16bit and 32bit I would doubt that.
Can you use the DLL outside of MATLAB? So create a small C/C++ application with calls that DLL. Does this work?
That would appear to be a good solution, using the DLL outside of MATLAB. Are you able to recommend any good documentation for creating an application using c or c++ in Visual studio that will allow me to call up functions in Matlab, from Visual studio, which then links to the DLL? I have not used c or c++ before so any hints to go about this would be great?
Thanks for your ideas, I am most grateful.
I meant using C/C++ and the DLL only to check if the DLL can be used at all (so no MATLAB involved here). There a several guides in the internet showing you how to use a DLL:
http://www.flipcode.com/archives/Creating_And_Using_DLLs.shtml

Connectez-vous pour commenter.

Plus de réponses (1)

In environment, select add-on. Search for MinGW-w64 Compiler and install. Just type in (mex -setup) without the parentheses in the command window once installation finishes.

Catégories

En savoir plus sur MATLAB Compiler dans Centre d'aide et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by