无法在Win7上使用MinGW编译RIES。

Can't compile RIES with MinGW on Win7

本文关键字:MinGW 编译 RIES Win7      更新时间:2023-10-16

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

>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:UsersXXXXXXAppDataLocalTempcczlkqve.o:ries.c:(.text+0xb9): undefined reference to `asprintf'
collect2: ld returned 1 exit status

谷歌现在沉默了...接下来我应该怎么做?

提前谢谢。

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。