【问题标题】:Can't compile RIES with MinGW on Win7在 Win7 上无法使用 MinGW 编译 RIES
【发布时间】:2012-04-25 12:26:12
【问题描述】:

我正在尝试在 Windows 7 上使用 MinGW 编译 this program。 在我第一次尝试时,它给了我这个错误:

>gcc -o ries.exe ries.c -lm

ries.c:1582:21: fatal error: stdafx.h: No such file or directory
compilation terminated.

我用谷歌搜索了一下,发现我应该删除 # include "stdafx.h" 行,我确实这样做了。

现在它给了我这个:

C:\Users\XXXXXX\AppData\Local\Temp\cczlkqve.o:ries.c:(.text+0xb9): undefined reference to `asprintf'
collect2: ld returned 1 exit status

Google 现在沉默了……接下来我该怎么做?

提前致谢。

【问题讨论】:

    标签: c++ gcc mingw


    【解决方案1】:

    MinGW 使用 (AFAIK) Microsoft C 运行时库。我不认为 asprintf 或类似的存在 - 尽管这很奇怪,因为他无论如何都包含了用于 Windows 构建的 stdafx.h,尽管不是以特别有用的方式(它不能 AFAICS 用于预编译的头文件因为它在 #if 中)

    最简单的解决方法是自己分配缓冲区,即更改

    char * name_ext;
    int nc;
    nc = asprintf(&name_ext, "%s.ries", filename);
    

    char name_ext[MAX_PATH];
    int nc;
    nc = snprintf(name_ext, MAX_PATH, "%s.ries", filename);
    

    如果没有定义 MAX_PATH(但我认为它会是:你已经有了 stdlib.h),那么要么自己定义它,要么只替换数字 260。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-10-17
      • 2021-10-26
      相关资源
      最近更新 更多