Search code examples
cvisual-studiomingwnmake

porting C compilation from MinGW to VisualStudio(nmake)


My current job at the university is to port a C program from MinGW (windows) to Visual Studio (nmake).

I have got a valid "makefile.vc" file for a very similar C program. My approach was to adopt the Makefile (i.e. "makefile.vc") to the program I need to port.

All but four C files seem to compile fine. Those four files have various errors for example, syntax errors and "unknown size".

Should I continue with my approach to change the Makefile or use CMAKE instead of nmake?

Is there a tutorial or any other pointer on porting a C program from MinGW/gcc to nmake?

typedef struct {
  A_TypeConverter *converter;
  char *domain;
} enumeratorConverterEntry;
static enumeratorConverterEntry enumeratorConverterEntries[]; /* line 186 */

error:

f.c(186) : error C2133: 'enumeratorConverterEntries' : unknown size


typedef struct AsmInstructionInfo {
  int flags;
  CONST char **argTypes; /* line 7 */
  int minArgs;
  int maxArgs;
  int cArgs;
} AsmInstructionInfo;

error:

fAssemble.c(7) : error C2061: syntax error : identifier 'CONST'

..

/* file fStack.c: */

#ifdef CHECK_ACTIVATION_COUNTS

/* code */
#endif

/* more code */

void fShowStack(l_Interp *interp) { /* line 94 */
    l_CallFrame *framePtr;

/* more code */

error:

 fStack.c(94) : error C2143: syntax error : missing ')' before '*'
 fStack.c(94) : error C2143: syntax error : missing '{' before '*'
 fStack.c(94) : error C2059: syntax error : ')'
 fStack.c(94) : error C2054: expected '(' to follow 'interp'

Solution

  • static enumeratorConverterEntry enumeratorConverterEntries[]; /* line 186 */
    

    That looks like a valid incomplete, forward declaration of an array, which would be valid syntax, except I think for the static qualifier. I don't have a copy of the 'C' standard in front of me, but reading between the lines on the results of Googling "forward declaration of static array" seems to indicate that an incomplete definition of a static array results in undefined behavior, so Microsoft and GNU are legitimately entitled to do whatever they want with it. GNU accepts it, and Microsoft rejects it. As Mark Wilkins points out you should be make the Microsoft compiler happy by replacing it with:

    extern enumeratorConverterEntry enumeratorConverterEntries[]; /* line 186 */
    

    In general it's worth noting that the Microsoft compiler only supports the C89 standard, while the GNU compiler supports portions of the C99 standard, and several of their own extensions, depending on the arguments to the compiler.

    The errors in fAssemble.c and fStack.c look like one or more preprocessor files are missing or incomplete. You should search your source to find out where CONST and l_Interp are defined, and then figure out why they are not being picked up in the files where the errors are occurring.