c - 将 C 编译从 MinGW 移植到 VisualStudio(nmake)

标签 c visual-studio mingw nmake

我目前在大学的工作是将 C 程序从 MinGW (windows) 移植到 Visual Studio (nmake)。

我有一个非常相似的 C 程序的有效“makefile.vc”文件。 我的方法是采用 Makefile(即“makefile.vc”)到我需要移植的程序中。

除了四个 C 文件之外,所有文件似乎都可以正常编译。这四个文件存在各种错误,例如语法错误和“未知大小”。

我应该继续采用我的方法来更改 Makefile 还是使用 CMAKE 而不是 nmake?

是否有关于将 C 程序从 MinGW/gcc 移植到 nmake 的教程或任何其他指示?

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

错误:

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;

错误:

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 */

错误:

 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'

最佳答案

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

这看起来像是一个有效的、不完整的数组前向声明,这将是有效的语法,除了我认为静态限定符之外。我面前没有“C”标准的副本,但是从谷歌搜索“静态数组的前向声明”结果的字里行间阅读似乎表明静态的定义不完整 em> 数组会导致未定义的行为,因此 Microsoft 和 GNU 有权对它做任何他们想做的事情。 GNU 接受它,而 Microsoft 拒绝它。正如 Mark Wilkins 指出的那样,您应该通过将其替换为以下内容来让 Microsoft 编译器满意:

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

一般来说,值得注意的是,Microsoft 编译器仅支持 C89 标准,而 GNU 编译器支持部分 C99 标准以及它们自己的几个扩展,具体取决于编译器的参数。

fAssemble.c 和 fStack.c 中的错误看起来像是一个或多个预处理器文件丢失或不完整。您应该搜索源代码以找出 CONST 和 l_Interp 的定义位置,然后找出发生错误的文件中没有拾取它们的原因。

关于c - 将 C 编译从 MinGW 移植到 VisualStudio(nmake),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8525470/

相关文章:

c - 没有说明符的 printf

c - 如何读取和输出带有空格和换行符的输入

c++ - 适用于 Dymola 的 Microsoft Visual C++ 编译器

c - Windows 上的 poll() c 函数

c - 未初始化的指针变量有什么用?

c - 在 realloc 中使用结构值会导致段错误

visual-studio - 停止 Visual Studio 2013 中的“在文件中查找”搜索,该搜索将花费很长时间

c# - 无法使用 Visual Studio 2017 和 C# 7.0 从方法返回元组

c - 如何在Windows 7中编译NetHack?

windows - MinGW/海湾合作委员会 : The application was unable to start correctly (0xc000007b)