2012-04-25 43 views
1
不能编译RIES

我试图编译使用MinGW的this program在Windows 7 我第一次尝试它给了我这个错误:使用MinGW Win7上

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

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

我用Google搜索了一下,发现我应该删除# 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 

谷歌现在是沉默......我应该怎么做?

在此先感谢。

回答

0

MinGW使用(AFAIK)Microsoft C运行时库。我不认为asprintf或其中存在相同的东西 - 尽管这很奇怪,因为他包含了stdafx.h for Windows生成,尽管不是特别有用(它不能用于预编译头文件,因为它是用#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.

+0

谢谢!它现在有效。 – Alda 2012-04-25 15:05:18