【发布时间】:2015-02-15 21:17:07
【问题描述】:
我最近安装了mingw-w64来学习c而不需要cygwin。问题是 mingw32-make 使用 g++ 编译我的 .c 源代码,但我真的不知道为什么。此处说明了该行为:
来源:
#include <stdio.h>
int main(int argc, char *argv[])
{
puts("Hello world.");
return 0;
}
这是生成文件:
CC = gcc -O
CFLAGS=-Wall -g
clean:
rm -f hello_world
使用 gnuwin32 版本的 make:
-> make hello_world
gcc -O -Wall -g hello_world.c -o hello_world
使用mingw32-make:
-> mingw32-make hello_world
g++ hello_world.c -o hello_world
有人可以解释一下,或者知道为什么会这样吗?使用 Cygwin 和 Linux,make 工具按预期使用 c 编译器(通常是 cc)。为什么 mingw32-make 使用 g++,而不是 gcc。 gcc 安装在 bin 目录下。
mingw-w64 是 2 天前最新的 winbuild
【问题讨论】:
-
您可以尝试使用
-x c强制C 编译。将其添加到您的CFLAGS。您还可以将CXX = gcc -O添加到您的makefile 中。如果它也没有得到尊重,那么它可能有助于进一步隔离问题。 -
感谢您的意见。使用 "CFLAGS=-Wall -g -x c" 不会导致所需的行为,但使用 CXX = gcc -O 确实会导致使用 gcc 作为编译器。我想这只是告诉 make 用 gcc 编译 c++ 文件?我想有点 hack。