Deploy mex file without dependencies - matlab

I am compiling some mex files that contain CUDA code.
With the right compiler installed, and CUDA installed in the machine, the compilation would always succeed and the code then works fine. Sometimes one can also use the same compiled .mexw64 (in the win64 case) in a different PC without the need of compiling it, as long as that PC has CUDA installed. However, if CUDA is not installed, the execution would fail because it can not find the needed libraries.
Is it possible to compile mex files and include any library/dependency on them, so they can, in most cases, just be copypasted into a new PC and execute?

Related

Linking with pe-i386 object file and a pe-x86-64 object file

Because my understanding of this problem is limited, please excuse me if I provide irrelevant details.
Question
I have two versions of MingGW on my computer, and both are 32-bit. The first one is what I call "basic MinGW", and it's the one I installed using mingw-get several years ago. The other one came with MSYS2.
Here are the constraints I am dealing with, details provided in the postscript:
My program depends on library A, which I can only compile from source using the MSYS2 MinGW.
My program depends on B.dll, a file that was provided to me. I do not have the source.
Using objdump, I discovered that B.dll has file format pe-i386
Using objdump, I discovered that programs compiled with the basic MinGW have file format pe-i386
Using objdump, I discovered that programs compiled with the MSYS2 MinGW have file format pe-x86-64
The end result is this:
My program cannot compile with the basic MinGW because library A (which must be compiled with MSYS2 MinGW) is incompatible
My program cannot compile with the MSYS2 MinGW because B.dll is incompatible
What is the difference between these two file formats? If they are both 32-bit, why can't I compile them together? Is it possible to convert B.dll to be compatible with the MSYS2 MinGW?
Details
Library A is libevent. At some point, libevent requires netioapi.h which does not appear to be present in the basic MinGW. However, MSYS2 MinGW is able to compile libevent.
B.dll is provided to me in Modelsim. It is the library you must link against fro compiling Verilog PLI programs.

Error running the rsim executable (Simulink Coder)

I have a simulink model (2016b with MC 2013 C/C++ and Mingw-64 compilers) that I'd like to generate a standalone executable for windows-64 bit.
I was able to run the grt executable but due to the fact that I need to read a mat file runtime as opposed to compile time, I am using rsim code generation for this purpose, however the executable that gets generated appears to need quite a bit of .dll, I provided the dll it was asking for however, the application still unable to run. This is the error that results
The application was unable to start correctly 0xc000007b. Click OK to
close the application
What am I missing ?
Your main program is compiled for x64 (64-bit) target, but the dll you provided is compiled for x86 (32-bit) target. Or vice versa.
If it is Mingw-64 stuff, you should be able to obtain all (or most) of them by using the official online installer. Link is here.

Matlab Run Time Compiler .exe

I'm know that its a beginner question but after I'm install the Matlab Compiler Runtime how can i run the matlab compiler from DOS?
I have the directory C:\Program Files\MATLAB\MATLAB Compiler Runtime
Where is the compiler .exe or something like that?
Thanks
Make sure that you actually have the MATLAB compiler as well. The Compiler Runtime and the compiler are two entirely different programs.
From the help, The MATLAB Runtime is a standalone set of shared libraries that enables the execution of compiled MATLAB applications or components on computers that do not have MATLAB installed.
Once you've compiled the exe (on a computer with MATLAB), you will move the exe to a computer without MATLAB, which has the compiler runtime installed.

Error: Invalid MEX file, the specified module could not be found

I have compiled Mex file successfully on my laptop. But when I am running it, it says Invalid mex file 'c:\newfolder\filename.mexw32' The specified module could not be found.
System specification:
OS: windows 7
MATLAB 2010a
Microsoft Visual Studio 2008.
The same mex file is compiled and run successfully on my PC under XP SP3.
This MathWorks support link suggests two possible reasons to your problem:
You do not have all of the necessary libraries that the MEX-function is dependent upon.
You are running a MEX-file on a different version of MATLAB than it was compiled on.
Either way, to locate the source of this error it says that you need to list all dependent library files and verify their existence in the system you're trying to run the MEX file on, and also recommends the Dependecy Walker as the tool to to do that.
Do you you the mex file on another system than the one it is created on?
If so, then you need to install the Microsoft Visual C++ Redistributable on that machine.
I had this problem also when upgrading from Matlab2010a/VS2008 to Matlab2013a/VS2010.
All my environment variables were sent correctly.
A reboot fixed problems with OpenCV dlls not being found, I assume that it was still trying to link to the OpenCV dlls for VS2008 (even though I had changed the path). However still my mex file could not find libmex.dll.
When I installed Matlab2013a, I did not uninstall the old version (in case I wanted to go back).
However that was the cause of my problem.
Once I uninstalled the old version of Matlab and rebooted again, the problem was gone.
I had a similar problem. I was only linking against 1 'lib' so I simply copied that lib into the same folder as the mexw64 and it worked.
I have not poked around for the correct place to tell MATLAB to add the lib's real location to whatever path it's looking at.

Recompile Arduino Target for Simulink for Windows 64 bit

I want to use Arduino Target for Simulink. It is made only for 32bit versions of Windows, but I read that you can recompile it and use it in 64-bit Windows.
I have tried, but I have not succeeded. I think that the files you need to create are the ones ending on .mexw32. What do you use to recompile these?
From http://www.mathworks.com/matlabcentral/fileexchange/24675-arduino-target:
To compile the C files for win64 (or
another platform), first make sure you
have a supported compiler:
http://www.mathworks.com/support/compilers/R2010b/win64.html
Once you have a compiler installed,
you can run "mex -setup" to point to
the appropriate compiler.
Finally, you can run "mex filename.c"
to compile all the functions in the
blocks directory.