Export c++ code from simulink scheme with s-function - c++

I have a simulink working simulink schema in which there are some s-function, I want to export this code in c++ and compile it. I already tried to export and compile a simple schema and it works, but when i try to compile the exported code of my project I get a lot of errors like
error: #error Unrecognized use
error: #error Must define one of RT,nNRT, MATLAB_MEX_FILE, SL_INTERNAL, or FIPXT_SHARED_MODULE
error: #error Unhandled case
error: ‘mxArray’ does not name a type mxArray **dlgParams; /* The S-function parameters
error: ‘mxArray’ has not been declared mxArray **)
error: ‘mxArray’ does not name a type mxArray *propVal;
error: ‘RTWSfcnInfo’ does not name a type; did you mean ‘RTWLogInfo’? RTWSfcnInfo sfcnInfo
The main settings that i used are:
Code generation system target file --> grt.tlc
language --> C++
Pack code and artifact --> <name_zip>
Tool chain GNU gcc/g++ | gmake (64-bit Linux)
default parameter behavior --> tuanble
code interface packaging --> nonreusable function
external mode --> chcked
standar math library --> c++ 03(ISO)
single output/update function --> checked
i used a fixed step size solver
Im using Ubuntu 18.
The source is generated succesfully the problem is when i try to compile the code.
Once the code is generate I get a zip folder with all the sources and also some external header file that I include when I make the CMakeLists.txt. I also tryied to compile directly the code with the .mk file but also I get a bounch of errors. The problem is realated with the s-function because I built a simple simulink schema with a source an s-function that implements a dynamical model and an output and when i generate the code and compile it I get the same errors. I also tryied to make a simple schema without s-function and this works. So is there any settings for the s-function to be exportable

At the end I found an answer that I post here in case someone else has my same problem.
The solution that worked form my is:
First of all once you have the generated zip file with all the sources and headers open it and load on the Matlab workspace the file buldinfo.mat then in the Matlab shell run
packNGo(buildInfo)
in this way you generate a new .zip with all the sources and headers, this .zip differs from the previous because is flat, no nested folder.
Inside this folder there is a file called define.txt with a list of variables, all these variables should be passed as flags to the compiler. For example in my case I use a CMakelists.txt so to set these flags I used
set(CMAKE_CXX_FLAGS "-Wall -Wextra -DMODEL=test_sum_gain -DNUMST=2 -DNCSTATES=2 -DRT -DUSE_RTMODEL -DON_TARGET_WAIT_FOR_START=0 -DCLASSIC_INTERFACE=0 -DALLOCATIONFCN=0 -DTID01EQ=1 -DEXT_MODE=1 -DMAT_FILE=0 -DONESTEPFCN=1 -DTERMFCN=1 -DMULTI_INSTANCE_CODE=0 -DINTEGER_CODE=0 -DMT=0")
this depends on the way in which you compile the source, but in any case you should set these variables that is I am not wrong are just a directive for the precompiler.
These two things worked for me.

Related

CGAL on Codeblock, compiler error

I'm trying to run the example "Scale_Space_Surface_Reconstruction_3" from CGAL library on CodeBlocks IDE on Ubuntu platform, as it would be nice
to have the IDE support for code completion and a more automatic configuration process.
I managed to successfully execute it by compiling it with cmake on the terminal window.
However, on CodeBlocks, after creating a new project and copying the code from the example, I get the following error:
/usr/local/include/CGAL/Scale_Space_Reconstruction_3/Scale_Space_Surface_Reconstruction_Impl_3.h:165:23: error: variable or field 'pca' declared void
Approximation pca( _nn[i]);
By looking inside the code, I found out that this is due to an undefined Macro CGAL_EIGEN3_ENABLED. As my experiment shows, if I define the macro at
pre-processing time, I do not get the same error. That is because, by defining the macro, the type definition Default::Get< wA,void>::type, becomes
Default::Get< wA, Weighted_PCA_approximation_3<Gt>>::type, and the compiler does not complain any more.
Unfortunately, as a deserved prize for messing with things I do not really understand, I get a segmentation fault at runtime.
How should I change the compiler options of codeBlocks to make the compilation succeed, and the executable run successfully?
I have the following include paths:
/usr/local/lib/CGAL/ /usr/local/include /usr/include /usr/include/eigen3.
I also included the following libraries:
libCGAL.so, libCGAL_Core.so, libCGAL_ImageIO.so, libgmp.so, libmpfr.so, libtbb.so, libtbbmalloc.so, libtbbmalloc_proxy.so

Building OpenSSL under Borland C++ Builder, Win 8.1

I'm following the instructions from INSTALL.W32 (various OpenSSL versions), in general it's:
* Configure for building with Borland Builder:
> perl Configure BC-32
* Create the appropriate makefile
> ms\do_nasm
* Build
> make -f ms\bcb.mak
Now, I do get two kind of errors when trying to build:
For OpenSSL < 1.0.0
nasmw -f obj -d__omf__ -ocrypto\md5\asm\m5_win32.obj .\crypto\md5\asm\m5_win32.asm
'nasmw' is not recognized as an internal or external command,
operable program or batch file.
Otherwise
Warning W8017 C:\CBuilder5\Include\sys/stat.h 34: Redefinition of 'S_IFMT' is not identical
Warning W8017 C:\CBuilder5\Include\sys/stat.h 35: Redefinition of 'S_IFDIR' is not identical
Error E2227 .\crypto\rand\randfile.c 226: Extra parameter in call to _open in function RAND_write_file
Warning W8053 .\crypto\rand\randfile.c 262: '_chmod(const signed char *,int,...)' is obsolete in function RAND_write_file
*** 1 errors in Compile ***
Yes, I feel bad for using Borland C++ Builder 5 but I can't do anything about it, and yes, I consider the Shining Light option if everything else fails.
I do not use OpenSSL but from your text some hints:
NASM
is not default assembler for Borland compilers
you need to download and install it first
(it is for free and one of the best compilers I used in the past)
you are missing some #define before including OpenSSL or including in wrong order
that is why you have the first warnings and most likely also the error
some libs need to add configuration #defines (added by some specific IDE's)
to specify what compiler,platform,endianess... is used
before any includes
usually if you include in wrong order then the defines are defined for some instances of a lib file but not for all
so try to reorder the includes
sometimes helps to include before the lib some other thing like conio,stdio,windows,...
to determine which define is missing or wrong open the stat.h
and look for #ifdef #ifndef statements around S_IFMT
The solution for the newest version (1.0.2d) was to:
remove the extra parameter from randfile (which, as comment stated, was unnecessary),
edit ms\bcb.mak, search for -DMD5_ASM -DSHA1_ASM -DRMD160_ASM
and change to -DMD5_NO_ASM -DSHA1_NO_ASM -DRMD160_NO_ASM . (there was an unresolved external error with SHA, MD5 and RMD160, they basically couldn't be compiled in asm).
There were some other steps included as well, but they're just specific to my environment.

IntelliSense error identifier "emlrtStack" is undefined

I am converting a MATLAB written function into C by "Matlab coder". After I get the converted files , the converted function always have first input argument as const emlrtStack *sp. Now when I am trying to test it on VC++ 2013, IntelliSense is giving mentioned above error.
I manually tried to locate this identifier in emlrt.h file but no such thing is present there. I tried to convert a simple multiply function with two input arguments[like, c=mul(a,b)] but still the converted function has this extra argument inside the function in addition to a and b.
(which means this argument is not function specific).
If someone has a solution to this or have experienced a problem like this, please share or help.
Moreover If someone know how to simply test these converted functions, it would be a much appreciated additional help .
It is likely that the code that was generated for a MEX function rather than a standalone target. MEX functions are binaries written C, C++ or Fortran that can be called like a normal MATLAB function. Generating code to produce a MEX function allows two things. First, you can test your generated code in MATLAB because you can call the MEX function from MATLAB like any other function. Look for a file named mul_mex.mex* after you do code generation and try to call it: mul_mex(1,2). The other use for generating a MEX function is that it can often be faster than the MATLAB code from which it was generated. MEX functions are only used in the context of MATLAB.
The parameter emlrtStack* that you saw appears in MEX generated code to aid in runtime error reporting. It is not present in standalone code that is designed to be run outside of MATLAB.
If you want to use the generated code in Visual Studio, or outside of MATLAB you should choose one of the standalone targets, LIB, DLL, or EXE. This page shows how to change the output type. To summarize, if using the command line you could say:
cfg = coder.config('lib'); %or 'dll' or 'exe'
codegen mul -config cfg -args {1,2}
If using the project interface, you click on the Build tab and choose static library or shared library in the "Output type" dropdown menu.
I would recommend reading this example that demonstrates how to use a generated DLL in Visual Studio.

Rinside compilation error with kdb

I sucessfully ran the sample codes in the package. Then I copied code from sample1 into another file of mine and set it up to compile using Makefile.
Also copied sample copies into the same directory.
The samples in the directory compile and run fine.
But using R in my already existing code is giving issues. When compiling it gives an error saying expected unqualified-id before âreturnâ. This happens in the line where I declare RInside R(argc, argv).
Another weird thing i noticed is if i include at the bottom of included files, I get a bunch of errors in Rcpp etc. but if i include it at the top, all those errors disappear.
Also, is the default compile option of -O3 required for the package? I have been using -Ofast for most of my codes. Browsing through the questions here I think I need to make changes to CXXFLAGS in Makevars but i can't find out where.
Any help appreciated.
I have boiled down the errors to another file included in my setup which is "k.h". This is a file which is used to interface c++ with kdb+ database. If I include the file before I get errors in Rcpp classes. When included after RInside, I get the earlier error of unqualified id before return.
This is the file in question: k.h
Resolved: It appears it was a variable name conflict. In all examples we have RInside R(argc, argv). As soon as I changed it to RInside L(argc, argv) everything worked fine. Don't know exactly why this was the case but it solves the problem at least. Tested outputs too.

Set Up iOS project to use eigen

I'm trying to set up an iOS project to compile a c++ library called Eigen for Linear Algebra maths.
I begin following the instructions of the Question mentioned in:
How to compile Eigen in iPhone
But there are still some kind of things I could not figure out.
User Stafan said to set the right compiler flags (-mfpu=neon -mfloat-abi=softfp). Where do I set those flags? I already found out to set flags for a single file like in http://meandmark.com/blog/2011/10/xcode-4-setting-compiler-flags-for-a-single-file/. But for what files do I need to set this flags? Especially the c++ files from the Eigen library do not appear here.
User Blukee said that he used armv7 optimized arch in build setting. In build settings I see in the Architectures category a green field saying Standard(armv7) is that what right?
I just created a ,,singleViewApplication'' and wanted to use the c++ files in an new Objective C class called MathLibary. Because some guys said that it is possible to mix up Objective C and C++ if I name the class MathLibary.hh and MathLibary.mm.
The class looks like
#import "MathLibary.hh"
#define EIGEN_DONT_VECTORIZE
#import "SVD.h"
#implementation MathLibary
#end
When I try to run the App the build fails an the compiler gives out some errors like:
In line 47 in SVD.h file, which is:
typedef typename NumTraits<typename MatrixType::Scalar>::Real RealScalar;
The error is Expected a qualified name after 'type name'
For me it sounds as that the compiler tries to compile the SVD.h as objective c file but is c++.
How do I change the compiler to compile both objective c files for the user interface and the c++ files from the library
I hope that somebody is able to help me, thanks a lot.
If you want to mix ObjC and C++, did you make sure to rename your file to have a ".mm" suffix? :)