Matlab code to C using Matlab coder - c

I have some working Matlab code, which I try to transform into C code using the Matlab coder. I am getting this error:
18 c:\users\bla\project\strcmpi.h(79) : warning C4028: formal parameter 2 different from declaration
19 c:\users\bla\project\strcmpi.h(79) : error C2371: 'strcmpi' : redefinition; different basic types
20 c:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\INCLUDE\string.h(245) : see declaration of 'strcmpi'
21 NMAKE : fatal error U1077: '"c:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\BIN\amd64\cl.EXE"' : return code '0x2'
22 Stop.
23 The make command returned an error of 2
24 'An_error_occurred_during_the_call_to_make' is not recognized as an internal or external command,
25 operable program or batch file.
It looks very C specific to me (I am not a proficient C programmer). Can anyone please point me in the right direction to overcome this error? Thanks.
PS:
Here is some adapted Matlab code:
if(strcmpi(parameters.x,'bladibla') == 1)
% some code
else
% some more code
end
where 'parameters' is a struct. I would like to stick to my struct but if there are better ways to achieve the above, especially in the context of the Matlab coder and C, please let me know.

The thing about strcmpi() (case-insensitive string comparison) is that it's not a standard C function. Thus, code that relies on it but tries to be portable across platforms sometimes has to provide its own implementation while deferring to the system's implementation if available. In my experience, the project's own strcmpi() implementation will be protected by a configuration option. If you open up c:\users\bla\project\strcmpi.h, you might see code similar to this:
#ifndef CONFIG_STRCMPI_PRESENT
int strcmpi(const char *string1, const char *string2);
#endif // CONFIG_STRCMPI_PRESENT
If you see this, the trick to getting around the problem will probably be to find the associated config.h file and uncomment the following line:
// #define CONFIG_STRCMPI_PRESENT
This is all just a guess based on my experience with similar issues.

Related

PRQA QAC terminates after encountering #error directive

I am new to QAC stuff and I am trying to set up QAC on my project. I am currently encountering this error when I try to run QAC on a file.
C:\Program Files (x86)\IAR Systems\Embedded Workbench 8.2\arm\inc\c\intrinsics.h ### 26 ### 869 ### [Q] '#error' directive: "Unknown compiler intrinsics version" Analysis terminated due to '#error' directive. ### 9
I have set the compiler personality file to not include the warnings from the folder above, but I am still seeing this error. Please kindly help on how to overcome this issue.
In general it is not a good idea to apply static analysis to headers provided with the compiler as they are tuned to the compiler in question and can contain any number of specialized constructions. In fact they may not even compile with another compiler and this is completely OK.
As an answer to the problem at hand, it looks like your static analysis tool is missing some of the macros that are predefined in iccarm. One way to solve this problem is to use the --predef_macros command line parameter to have the compiler output a file containing all predefined macros (as C source code). The content of this file can be used to set up the static analysis environment.

Preprocessor: error: missing binary operator before token "("

we're curruntly working on a C project and we've downloaded and used the header dirent.h, the problem is the code was compiled successfully on my teammate laptop but in mine it doesn't compile, telling me this :
In file included from utils.c:6:0:
dirent.h: In function '_wopendir':
dirent.h:383:28: error: missing binary operator before token "("
#if WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_DESKTOP)
^
dirent.h:405:28: error: missing binary operator before token "("
#if WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_DESKTOP)
^
dirent.h:413:5: warning: implicit declaration of function 'wcsncpy_s' [-Wimplicit-function-declaration]
wcsncpy_s (dirp->patt, n+1, dirname, n);
^
I searched for the problem and find that it's a preproccessor error and currently on the #if
i've tried to add #define WINAPI_FAMILY_PARTITION(Partitions) but it doesn't work.
Please suggest me a solution to compile it successfully, and does the windows version affect on preprocessing?
WINAPI_FAMILY_PARTITION is defined in <winapifamily.h>, probably included by <windows.h>. Look at this question for more explanations, but windows intricacies are largely irrelevant for your compilation issue. You might want include <windows.h> before <dirent.h>?
You did not publish the source code for your program, nor did you specify what OS you compile for not what compiler you use, but you mention we've downloaded and used the header dirent.h... This sounds wrong: system include files such as <dirent.h> are automatically installed with the compiler, they are specific to the OS and compiler, you cannot just download one from the net and expect it to work on your system. It might work by chance on your teammate's PC because the OS might be different.

unscoped enums in C code with VS2015

I'm trying to compile the psutil module for Python, using VS 2015 and the Windows 10 SDK. Compilation fails with the following error:
c:\users\builder\documents\code\psutil\psutil\arch\windows\ntextapi.h(212): error C2365: 'ProcessBreakOnTermination': redefinition; previous definition was 'enumerator'
C:\Program Files (x86)\Windows Kits\10\include\10.0.10240.0\um\winternl.h(308): note: see declaration of 'ProcessBreakOnTermination'
c:\users\builder\documents\code\psutil\psutil\arch\windows\ntextapi.h(212): error C2086: '_PROCESSINFOCLASS2 ProcessBreakOnTermination': redefinition
c:\users\builder\documents\code\psutil\psutil\arch\windows\ntextapi.h(212): note: see declaration of 'ProcessBreakOnTermination'
Further investigation shows ProcessBreakOnTermination is part of an enum (PROCESSINFOCLASS) in winternl.h.
I believe this has to do with C++11's enforcement of scoped enums: https://msdn.microsoft.com/en-us/library/vstudio/2dzy4k6e(v=vs.110).aspx
However, I am lost on how to address this issue. If I try to add the class or struct bits as detailed on that MS website, I get compiler errors, since this is being compiled as C code. Why should the C++11 rules apply to C code here?
The solution I came up with was to wrap the offending dual-defined symbols in a #if.
(start of enum)
(last good entry)
#if _MSC_VER < 1900
(offending enum entry)
#endif
(next entry) = (last_good_entry)+2
Any nicer solutions are welcome!

Compilation error in visual C++

I am using Visual studio 2010 for building C project. My project contains a number of header files,source file and parsers. It uses lex and bason files. I am getting a single error during the compilation and íé the following
abc.y:error C2065: 'INPUT' : undeclared identifier
I tried the solutions I am getting like including
#define WIN32_WINNT >= 0x0501
in my main.c file before the inclusion of any of the header files.I am not able to get rid of this error. Could you please let me know what Can be the reasons for this error?
EDIT
The snippet of code that is showing error is:
list_Cons(0, list_List((POINTER)INPUT)
The surprising thing is that If i alter INPUT into INPUT1, I get the same error. It is stoic to change.
Presumably you read this and this.
#define WIN32_WINNT >= 0x0501 wont work. You should try using #define WIN32_WINNT 0x0501 instead.
Also, check that you are actually #including winuser.h
A C++ compiler cannot process a *.y file. For that you need a yacc / bison program, which does not come included with Visual Studio 2010.
For myself I use CMake which can generate MSVC projects along with other build types. You can tell it that a .y needs to be processed outwith the C/C++ files and it will instruct MSVC to invoke whatever external tools are necessary to preprocess the non-C/C++ parts.

Is there a tool to make a c compiler in win7 with yacc and lex?

The only tool is found is this Parser Generator:
Operating System: Windows 95 / 98 / ME / NT / 2000 / XP
But seems it's not supporting win7,when I try to build for Visual C++(32 bit), got this error:
yyaslvar.c
C:\Program Files\Parser Generator 2\Cpp\Source\yyaslvar.c(35) : error C2099: initializer is not a constant
C:\Program Files\Parser Generator 2\Cpp\Source\yyaslvar.c(36) : error C2099: initializer is not a constant
C:\Program Files\Parser Generator 2\Cpp\Source\yyaslvar.c(37) : error C2099: initializer is not a constant
FILE YYFAR *YYNEAR YYDCDECL yyin = stdin;
FILE YYFAR *YYNEAR YYDCDECL yyout = stdout;
FILE YYFAR *YYNEAR YYDCDECL yylexererr = stderr;
I'm using Visual Studio 2010 Express.
I don't know about VS2010, but I've used this Win32 port of Lex/Yacc (Flex/Bison) on VS2005 without problems: http://userpages.monmouth.com/~wstreett/lex-yacc/lex-yacc.html
Also, your error is due to the fact that VC++ actually defines stdin, stdout etc. as macros which expand to function calls that return a FILE *. Clearly, these are not compile-time constants, which is what the error says.
Not so easy with windows. If you are ready to shell out some money , then you can use MKS lex and Yacc toolkit
http://www.mkssoftware.com/products/ly/
The problem has nothing to do with Win7 per se, and everything to do with (stricter!) ANSI C standards. The C compiler simply won't let you assign a macro (like "stdin" or "stdout") to a "non-automatic variable":
http://msdn.microsoft.com/en-us/library/t801az8a%28VS.80%29.aspx
Here's one workaround:
http://coding.derkeiler.com/Archive/C_CPP/comp.lang.c/2009-10/msg00982.html
stdin and stdout need not be constants, so you can't use them to
initalise static or global variables.
Do the assignments in an initialisation function instead.
Moreover, this link might get you pointed in the right direction:
http://msdn.microsoft.com/en-us/library/aa730877%28VS.80%29.aspx
'Hope that helps

Resources