无法在Win7上使用MinGW编译RIES。
Can't compile RIES with MinGW on Win7
我正在尝试在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。
相关文章:
- 尝试在Windows上执行C++时出错(通过MinGW编译)
- 如何使用mingw编译C STD ::线程代码
- MinGW 编译的可执行文件与网络无法在 x64 系统上运行
- MinGW编译的exe-缺少libgcc_s_silj-1.dll
- 使用由 Mingw 5.3 编译的 boost ASIO 库使用 QT 时出错
- 如何在 Atom IDE 中使用 gpp-compiler 时更改 MinGW 编译的 exe 位置?
- mingw 编译错误:从 'FARPROC ' 到 'void*' 的转换无效,但 msvc 编译正常
- 使用 MinGW 编译具有网络代码的简单 C++ SFML 文件会引发错误"undefined reference to IpAddress"
- 使用 mingw 编译 opencv3.1
- libx264用mingw编译 - 缺少__umoddi3,__udivdi3,_fseeko64和____chkstk
- MinGW .h 编译文件不起作用:此文件的版本与您运行的 Windows 版本不兼容
- 尝试使用 MinGW 编译 Assembly + C++:ccqKAvXJ.o:main.cpp:(.text+0x18):对 'GetMagicNumber' 的未定义引用
- std::endl 导致使用 MinGW 编译的 Windows 8 崩溃
- 用mingw编译SDL2,使用崇高的文本2错误
- MinGW编译失败:我创建的头文件没有这样的文件或目录
- 获取记事本++以使用minGW编译和运行C++程序
- 使用小型转储和 GDB 分析崩溃,以便 mingw 编译的可执行文件
- 使用 MinGW 编译自动化代理
- 无法在Win7上使用MinGW编译RIES。
- Qt5:此代码使用msvc2012编译正常,但使用MinGW编译时出现错误..为什么?