fmanghi

The compilation phase in my openplc procress exits with the errors shown below.
It seems to be related to the Res0.c file compiled during the arduino compilation process.


In file included from C:\Users\Francesco Manghi\OpenPLC_Editor\editor\arduino\src\Config0.c:10:0:
C:\Users\Francesco Manghi\OpenPLC_Editor\editor\arduino\src\POUS.h:297:0: error: unterminated argument list invoking macro "__DECLARE_VAR"
__DECLARE_VAR(BOOL

C:\Users\Francesco Manghi\OpenPLC_Editor\editor\arduino\src\POUS.h:1:0: error: unterminated #ifndef
#ifndef __POUS_H

C:\Users\Francesco Manghi\OpenPLC_Editor\editor\arduino\src\POUS.h:297:3: error: expected specifier-qualifier-list before '__DECLARE_VAR'
__DECLARE_VAR(BOOL
^~~~~~~~~~~~~
In file included from C:\Users\Francesco Manghi\OpenPLC_Editor\editor\arduino\src\POUS.c:1:0:
C:\Users\Francesco Manghi\OpenPLC_Editor\editor\arduino\src\POUS.h:297:0: error: unterminated argument list invoking macro "__DECLARE_VAR"
__DECLARE_VAR(BOOL

In file included from C:\Users\Francesco Manghi\OpenPLC_Editor\editor\arduino\src\POUS.c:1:0:
C:\Users\Francesco Manghi\OpenPLC_Editor\editor\arduino\src\POUS.h:1:0: error: unterminated #ifndef
#ifndef __POUS_H

In file included from C:\Users\Francesco Manghi\OpenPLC_Editor\editor\arduino\src\POUS.c:1:0:
C:\Users\Francesco Manghi\OpenPLC_Editor\editor\arduino\src\POUS.h:297:3: error: unknown type name '__DECLARE_VAR'
__DECLARE_VAR(BOOL
^~~~~~~~~~~~~
C:\Users\Francesco Manghi\OpenPLC_Editor\editor\arduino\src\POUS.c:4:6: error: expected ':', ',', ';', '}' or '__attribute__' before 'CLIMATICA_EST'
BOOL CLIMATICA_EST(
^~~~~~~~~~~~~
C:\Users\Francesco Manghi\OpenPLC_Editor\editor\arduino\src\POUS.c:1012:0: error: unterminated argument list invoking macro "__SET_EXTERNAL"
__SET_EXTERNAL(data__->,CLIM_CALC

In file included from C:\Users\Francesco Manghi\OpenPLC_Editor\editor\arduino\src\Res0.c:13:0:
C:\Users\Francesco Manghi\OpenPLC_Editor\editor\arduino\src\POUS.h:297:0: error: unterminated argument list invoking macro "__DECLARE_VAR"
__DECLARE_VAR(BOOL

C:\Users\Francesco Manghi\OpenPLC_Editor\editor\arduino\src\POUS.h:1:0: error: unterminated #ifndef
#ifndef __POUS_H

C:\Users\Francesco Manghi\OpenPLC_Editor\editor\arduino\src\POUS.h:297:3: error: unknown type name '__DECLARE_VAR'
__DECLARE_VAR(BOOL
^~~~~~~~~~~~~
In file included from editor\arduino\src\lib/iec_std_FB.h:35:0,
from editor\arduino\src\lib/iec_std_lib.h:746,
from C:\Users\Francesco Manghi\OpenPLC_Editor\editor\arduino\src\Res0.c:6:
C:\Users\Francesco Manghi\OpenPLC_Editor\editor\arduino\src\Res0.c:16:23: error: expected ':', ',', ';', '}' or '__attribute__' before 'RES0__CLOUD_OK'
__DECLARE_GLOBAL(BOOL,RES0,CLOUD_OK)
^
editor\arduino\src\lib/accessor.h:10:19: note: in definition of macro '__DECLARE_GLOBAL'
__IEC_##type##_t domain##__##name;\
^~~~~~
In file included from C:\Users\Francesco Manghi\OpenPLC_Editor\editor\arduino\src\Res0.c:69:0:
C:\Users\Francesco Manghi\OpenPLC_Editor\editor\arduino\src\POUS.h:1:0: error: unterminated #ifndef
#ifndef __POUS_H


Error during build: exit status 1

COMPILATION FAILED!


File Res0 found as attachment.
Is there a reason for this behaviour?

Thanks a lot,
best regards.

Reply 0 0
fmanghi
Well, also POUS.h and POUS.c


  // PROGRAM private variables - TEMP, private and located variables
  __DECLARE_EXTERNAL(REAL,BMS_IN_1)
  __DECLARE_EXTERNAL(REAL,BMS_IN_2)
  __DECLARE_EXTERNAL(REAL,BMS_IN_3)
  __DECLARE_EXTERNAL(REAL,BMS_IN_4)
  __DECLARE_EXTERNAL(BOOL,RELAY_CMD)
  __DECLARE_EXTERNAL(BOOL,CLOUD_OK)
  __DECLARE_EXTERNAL(REAL,CLOUD_SP_1)
  __DECLARE_EXTERNAL(REAL,CLIM_CALC_1)
  __DECLARE_EXTERNAL(REAL,SETPOINT_CHANNEL_1)
  __DECLARE_EXTERNAL(INT,MODO_CANALE_1)
  __DECLARE_VAR(BOOL,_TMP_OUTPUT_SELECTOR18_OUT)
  __DECLARE_VAR(REAL,_TMP_OUTPUT_SELECTOR18_OUT_SP)
  __DECLARE_VAR(BOOL,_TMP_OUTPUT_SELECTOR18_RELAY_OUT)
} MODE_TO_FIELD;



and 

#include "POUS.h"
// FUNCTION
BOOL CLIMATICA_EST(
  BOOL EN, 
  BOOL *__ENO, 
  REAL SUP_MAX, 
  REAL SUP_MIN, 
  REAL EXT_MAX, 
  REAL EXT_MIN, 
  REAL *__SETPOINT_OUT, 
  REAL T_EXT)
{
  BOOL ENO = __BOOL_LITERAL(TRUE);
  REAL SETPOINT_OUT = 0;
  BOOL CLIMATICA_EST = __BOOL_LITERAL(FALSE);
  // Control execution
  if (!EN) {
    if (__ENO != NULL) {
      *__ENO = __BOOL_LITERAL(FALSE);
    }
    return CLIMATICA_EST;
  }
  if ((T_EXT < EXT_MIN)) {
    SETPOINT_OUT = SUP_MAX;
  } else if ((T_EXT > EXT_MAX)) {
    SETPOINT_OUT = SUP_MIN;
  } else {
    SETPOINT_OUT = ((((T_EXT - EXT_MIN) / (EXT_MAX - EXT_MIN)) * (SUP_MAX - SUP_MIN)) + SUP_MIN);
  };
  goto __end;
__end:
  if (__ENO != NULL) {
    *__ENO = ENO;
  }
  if (__SETPOINT_OUT != NULL) {
    *__SETPOINT_OUT = SETPOINT_OUT;
  }
  return CLIMATICA_EST;
}
Reply 0 0
thiagoralves
It would be useful to post the program that is actually generating those compilation errors
Reply 0 0
fmanghi
Heeere it goes @thiagoralves ! 🙂
Reply 0 0
thiagoralves
Hi @fmanghi I took a look at your project, and it seems that the MatIEC compiler is crashing while compiling it, generating an incomplete output. That's why you face these errors. You can check the compilation output that there is a "Internal compiler error in file ./ generate_location_list.cc at line 150" message in there. I don't know what is causing this compiler crash. It could be something wrong with your code that the compiler cannot provide a proper error message and crashes, or could be something else. I do not maintain MatIEC, which it makes it harder for me to debug. Meanwhile, my suggestion to you is to copy/paste portions of your program into a new project and try to compile that. Continue adding more and more blocks until you face that MatIEC crash again. That will give us a better picture of what might be causing the crash.
 
PS: I noticed that you have tons of "external" variable declarations in your program. It does not make sense to have an "external" variable without a global variable for it to link to. I noticed that although you have all these "external" variables, you don't have any global variable defined. This could be one portion of the problem.
Reply 0 0
fmanghi
Hi @thiagoralves, they are decleared in a certain area of the code.
BTW, i tried moving them in 2 different areas of the code to see if there was any difference and no, no luck.
It's clearly a compiler problem.
I'm guessing if it can be found a different release version of the compiler, just to test.

I'll try also with the "unpacking" of the code as suggested, just to understand if i can find something.
 
TY
Reply 0 0
thiagoralves
The only place where you can declare global variables is in the project Resources (Res0). If you don’t have variables declared there, then it is not a global variable 
Reply 0 0
fmanghi
Screenshot 2023-03-09 144102.png
 
Decleared (in a newer version maybe with respect to yours)
Same result.
Reply 0 0
thiagoralves
I’ve done that too, so I knew it was not the entirety of the problem. I just said that because in the future you would definitely have problems running this program without the global declarations. 

If you can work on splitting the program to see where it crashes it would be great. Meanwhile I will try to analyze the compiler to see why it is crashing
Reply 0 0
Reply