How to use FMIKit in 64-bit Matlab / Simulink to generate 32-bit binary FMU? - matlab

I have successfully used FMIKit2.7(from [https://github.com/CATIA-Systems/FMIKit-Simulink] )in 64-bit Matlab / Simulink (Matlab2017a) to generate a 64-bit binary FMU, which is indeed useful. However, now other simulation tools need to use 32-bit binary FMU for co-simulation, I follow the following way:
[ https://ww2.mathworks.cn/help/coder/ug/build-32-bit-dll-on-64-bit-windows(r)-platform-using-msvc-toolchain.html?s_tid=srchtitle]
Added a 32-bit compiler toolchain to 64-bit Matlab.
In addition, Intel-> x86-32 (Windows32) is selected for Hardware Implementation, and rtwsfcnfmi.tlc is selected for System Target File. The FMI Option sets the output to a Co-Simulation type FMU.
Hardware Implementation
System Target File
FMI Option
However, in fact, the FMU generated by FMIKit is still a 64-bit binary FMU.
My guess is that FMIKit automatically chose a 64-bit compiler during the compilation and linking process. What do I need to do to modify the FMIKit configuration file (such as a .tlc file or others) or Matlab / Simulink to generate a 32-bit binary FMU?

You should use the grtfmi.tlc target insted of the rtwsfcn.tlc target.
Then you either manage to configure the cmake-build to directly generate a 32-bit FMU. (I am not familiar with this. But there are offered different cmake generators for different VisualStudio versions, some of them having a 64 in the name. So are the others 32bit?)
As an alternative:
check "Include Sources in FMU"
Then you can afterwards compile the FMU e.g. using fmpy (command line or gui --> help --> add platform binary) from a 32-bit python version. You cannot use the Anaconda installation for the latest fmpy version in 32bit, see https://github.com/CATIA-Systems/FMPy/issues/64.

Related

why does the error regarding gcc is occuring in matlab?

I have download that code from github.
Whenever that code tries to check mexopencv (a file inside lib folder). It shows an error on Matlab 2017a that is:
[error 3] please make sure gcc >= 4.4 g++ >= 4.4 is installed ...
I am having a gcc version of 8.8.0
Following is the description of system
Window 10
Visual Studio 2012
Matlab 2017a
opencv 2.4.10
mexopencv (install from your folder LIB)
You might lack of standard libraries (.dll in Windows but .lib in Linux). The code was developed under Linux (help is also only provided for Linux systems) and once tested under Windows 7.
The method was tested under OS linux lubuntu 14.04, CPU intel i5 and
16GB of RAM. This guide was written under a linux-based distribution
scope, more precisely debian. Unfortunately we lack experience to
address bugs or any problem that could emerge in non-linux OS, we will
provide only linux OS help regarding execution problems, we apologise.
we tested this code on Windows7. We successfully installed opencv
2.4.10 following this tutorial: [http://www.learnopencv.com/install-opencv3-on-windows/]
This suggests that the mex-function is also linux-based. The error should vanish if you compile the source code yourself on your system, e.g. with MinGW (also GCC), see here.
EDITED:
the README.markdown file (under LIB/mexopencv-master.zip) provides a little guide through the installation process of both, openCV and the mexopencv function for unix (including ubuntu 14.04) and Windows systems. The latter states:
Browse to mexopencv root folder, and type the following in the MATLAB
command window:
>> mexopencv.make
By default, mexopencv assumes the OpenCV library is installed in
C:\opencv. If this is not the case, specify the path as an argument:
>> mexopencv.make('opencv_path', 'c:\your\path\to\opencv')
Note that if you build OpenCV from source, this path specification
might not work out of the box. You need to replace dll files in the
OpenCV package with newly built binaries. Or, you need to modify
+mexopencv/make.m to correctly link your MEX-files with the library.
To remove existing mexopencv binaries, use the following command.
>> mexopencv.make('clean', true)
It requires a standard C++ compiler supported by Matlab (see here), any Visual Studio installation should be OK, as an open-source option MinGW is recommended. Just remember to pick the right system (usually 64-bit).

Compile standalone Matlab guide program for Windows using Ubuntu

I'm using Matlab R2016a. I'm following this video to compile my Matlab guide program as standalone application. However I can only see options to compile it for a Linux platform. Is it also possible to compile it for Windows using the Linux version of Matlab?
Sadly, at present, the answer to your question is no. In Matlab you cannot achieve cross compilation of executables. The Matlab Compiler is strictly tied to the machine environment.
The basic rule is that in order to build an executable that can run under operating system X, it must be compiler under operating system X.
Therefore, you need to install the Matlab Compiler on a Windows machine to create an executable that can run under Windows. On the top of that, Windows represents a special case in which you have to consider the difference between 32 and 64 bit versions. For more infos, read these threads:
https://it.mathworks.com/matlabcentral/answers/4649-deploy-for-windows-32-bit-from-a-64-bit-computer
https://it.mathworks.com/matlabcentral/answers/217297-32-bit-exe-compilation-using-matlab-64-installed
https://it.mathworks.com/matlabcentral/answers/60904-compile-executable-for-64-bit-system

libfaad2.dll is not a valid win32 application - dependency error kernel32.dll

Win7 Service Pack 1
Matlab 2013b
Hello
I am trying to include a libfaad2.dll lib (which I got ready compiled) to Matlab so I can use the functions. I try this with the loadlibrary command.
But I get the error message
libfaad.dll is not a valid win32 application!
from matlab.
A short examination of libfaad2.dll with DependencyWalker (x64 Version) showed that it needs c:\windows\system32\Kernel32.dll. But there is also shown that 2 functions are not available in kernel32.dll
---> So I guess this is not a Matlab Problem
BUT the c:\windows\sysWow64\kernel32.dll includes the desired functions!
How can I tell matlab, or generally, that the libfaad2.dll file should use the sysWow64\kernel32.dll ?
Found a solution: Installing 32 bit version of Matlab and try with this. Worked at first try!
More detailed: Win7 has 2 different folders for system .dlls
C:\windows\system32: Here are all the .dlls for 64-bit software and not for 32!
C:\windows\SysWoW64: WoW64 stands for "Windows on 64-bit Windows", and it contains all the 32-bit binary files required for compatibility, which run on top of the 64 bit Windows.
Using 32-bit version, Matlab will use the SysWoW64 files. And that is the rigth kernel32.dll which contains all the functions needed!

How to start SVM training on MATLAB

I have a set of facial features that i have obtained and would like to classify using SVM. I intend to use libsvm package and use MATLAB to carry out the training.I have already read up on SVM by watching the Stanford lecture. But I am not sure how to use libsvm to start.. Need some guidance...
In matlab you can link your matlab code with some programs implemented in c. This a called a mex-file.
However you need to compile them, to make it work.
You can read the readme file to know how to compile them:
Installation
On Unix systems, we recommend using GNU g++ as your compiler and type
'make' to build 'svmtrain.mexglx' and 'svmpredict.mexglx'. Note that
we assume your MATLAB is installed in '/usr/local/matlab', if not,
please change MATLABDIR in Makefile.
Example:
linux> make
To use Octave, type 'make octave':
Example: linux> make octave
On Windows systems, pre-built binary files are already in the
directory `..\windows', so no need to conduct installation. Now we
include both 32bit binary files and 64bit binary files, but in future
releases, we will provide binary files only for 64bit MATLAB on
Windows. If you have modified the sources and would like to re-build
the package, type 'mex -setup' in MATLAB to choose a compiler for mex
first. Then type 'make' to start the installation.
Example:
matlab> mex -setup
(ps: MATLAB will show the following messages to setup default compiler.)
Please choose your compiler for building external interface (MEX) files:
Would you like mex to locate installed compilers [y]/n? y
Select a compiler:
1 Microsoft Visual C/C++ version 7.1 in C:\Program Files\Microsoft Visual Studio
[0] None
Compiler: 1
Please verify your choices:
Compiler: Microsoft Visual C/C++ 7.1
Location: C:\Program Files\Microsoft Visual Studio
Are these correct?([y]/n): y
matlab> make
For list of supported/compatible compilers for MATLAB, please check
the following page:
http://www.mathworks.com/support/compilers/current_release/

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.