Opened 8 years ago

Last modified 8 years ago

#4032 new defect

Using Extern C function compiler generates duplicate variables.

Reported by: guillegiraldo@… Owned by: Lennart Ochel
Priority: blocker Milestone: Future
Component: Code Generation Version: v1.9.4-v1.9.x
Keywords: Cc:

Description

When using an external C function, the simulation returns the following error:

Error: Error building simulator. Build log: gcc    -falign-functions -msse2 -mfpmath=sse      -I"C:/OpenModelica1.9.6//include/omc/c" -I. -DOPENMODELICA_XML_FROM_FILE_AT_RUNTIME  -c -o IntegrateInterpolatedExternalVector.o IntegrateInterpolatedExternalVector.c
gcc    -falign-functions -msse2 -mfpmath=sse      -I"C:/OpenModelica1.9.6//include/omc/c" -I. -DOPENMODELICA_XML_FROM_FILE_AT_RUNTIME  -c -o IntegrateInterpolatedExternalVector_functions.o IntegrateInterpolatedExternalVector_functions.c
gcc    -falign-functions -msse2 -mfpmath=sse      -I"C:/OpenModelica1.9.6//include/omc/c" -I. -DOPENMODELICA_XML_FROM_FILE_AT_RUNTIME  -c -o IntegrateInterpolatedExternalVector_records.o IntegrateInterpolatedExternalVector_records.c
gcc    -falign-functions -msse2 -mfpmath=sse      -I"C:/OpenModelica1.9.6//include/omc/c" -I. -DOPENMODELICA_XML_FROM_FILE_AT_RUNTIME  -c -o IntegrateInterpolatedExternalVector_01exo.o IntegrateInterpolatedExternalVector_01exo.c
gcc    -falign-functions -msse2 -mfpmath=sse      -I"C:/OpenModelica1.9.6//include/omc/c" -I. -DOPENMODELICA_XML_FROM_FILE_AT_RUNTIME  -c -o IntegrateInterpolatedExternalVector_02nls.o IntegrateInterpolatedExternalVector_02nls.c
IntegrateInterpolatedExternalVector_functions.c: In function 'omc_VectorTable_destructor':
IntegrateInterpolatedExternalVector_functions.c:14: error: redeclaration of '_table_ext' with no linkage
IntegrateInterpolatedExternalVector_functions.c:13: note: previous declaration of '_table_ext' was here
IntegrateInterpolatedExternalVector_functions.c:17: error: void value not ignored as it ought to be
mingw32-make: *** [IntegrateInterpolatedExternalVector_functions.o] Error 1
mingw32-make: *** Waiting for unfinished jobs....
RESULT: 2

I went to file IntegrateInterpolatedExternalVector_functions.c (attached) and found that variables are actually being declared twice.

Attachments (2)

source.rar (1.5 KB ) - added by guillegiraldo@… 8 years ago.
Source code to reproduce behavior. Need to change c file path in mo file.
IntegrateInterpolatedExternalVector_functions.c (2.0 KB ) - added by guillegiraldo@… 8 years ago.
Generated c file with duplicate variable definition (lines 13-16)

Download all attachments as: .zip

Change History (3)

by guillegiraldo@…, 8 years ago

Attachment: source.rar added

Source code to reproduce behavior. Need to change c file path in mo file.

by guillegiraldo@…, 8 years ago

Generated c file with duplicate variable definition (lines 13-16)

comment:1 by Martin Sjölund, 8 years ago

It is declared twice because you used table on both left side and in the call to the destructor. The destructor function does not have any outputs anyway, so leave that out.

Before:

  function destructor "Release storage"
    input VectorTable table;
    external "C" table=destroyVectorTable(table)

Fixed:

  function destructor "Release storage"
    input VectorTable table;
    external "C" destroyVectorTable(table)

I believe generating code for table twice if it occurs twice in the external call to be an error (Modelica spec seems to allow this use-case).

Note: See TracTickets for help on using tickets.