简体   繁体   English

ming32-make使用g ++而不是cc或gcc来编译.c源文件

[英]ming32-make is using g++ instead of cc or gcc to compile a .c source file

I recently installed mingw-w64 to learn c without needing cygwin. 我最近安装了mingw-w64来学习c而不需要cygwin。 The issue is that mingw32-make is using g++ to compile my .c source, but I don't really know why. 问题是mingw32-make使用g ++来编译我的.c源代码,但我真的不知道为什么。 The behavior is illustrated here: 这里说明了这种行为:

here's the source: 这里是来源:

#include <stdio.h>
int main(int argc, char *argv[])
{
    puts("Hello world.");
    return 0;
}

here's the makefile: 这是makefile:

CC = gcc -O
CFLAGS=-Wall -g
clean:
    rm -f hello_world

using gnuwin32 version of make: 使用gnuwin32版本的make:

-> make hello_world
gcc -O -Wall -g    hello_world.c   -o hello_world

using mingw32-make: 使用mingw32-make:

-> mingw32-make hello_world
g++     hello_world.c   -o hello_world

Can someone explain this, or know why its happening? 有人能解释一下,还是知道它为什么会发生? Using Cygwin, and also using Linux, the make tool uses a c-compiler (usually cc) as expected. 使用Cygwin,也使用Linux,make工具按预期使用c编译器(通常是cc)。 Why does mingw32-make use g++, instead of gcc. 为什么mingw32-make使用g ++而不是gcc。 gcc is installed in the bin directory. gcc安装在bin目录中。

mingw-w64 is the latest winbuild as of 2 days ago mingw-w64是2天前最新的winbuild

mingw32-make (correctly IMO) treats the file system as case insensitive, so foo.c and FOO.C refer to the same file. mingw32-make(正确的IMO)将文件系统视为不区分大小写,因此foo.c和FOO.C引用相同的文件。

Your makefile lacks any explicit rule for your hello_world goal, so built-in implicit rules must be used; 你的makefile缺少hello_world目标的任何明确规则,因此必须使用内置的隐式规则; it seems that the COMPILE.C rule is being matched for hello_world.c, before the COMPILE.c rule; 在COMPILE.c规则之前,似乎COMPLO.C规则与hello_world.c匹配; COMPILE.C is a default rule for compiling C++, so the appropriate compiler is used. COMPILE.C是编译C ++的默认规则,因此使用适当的编译器。

As you note, setting CXX = gcc is kludgy, and fundamentally wrong; 如你所知,设置CXX = gcc是kludgy,从根本上说是错误的; it will break if your project expands to requiring mixed C and C++ components. 如果您的项目扩展到需要混合的C和C ++组件,它将会中断。 A more appropriate solution is to provide your own rule ... either an explicit rule, or a pattern rule, to direct mingw32-make to use $(CC) for compiling *.c (and *.C) files, so that the built-in default rules will not apply. 更合适的解决方案是提供您自己的规则...显式规则或模式规则,以指示mingw32-make使用$(CC)来编译* .c(和* .C)文件,以便内置默认规则将不适用。 You can then keep CXX = g++ for compiling any *.cpp files, (recommended for compatibility with MSVC convention), which your project may include. 然后,您可以保留CXX = g ++以编译任何* .cpp文件(建议与MSVC约定兼容),您的项目可能包含这些文件。

This has been confirmed to be a problem inside GNU Make, present in builds that enabled the case-insensitive filesystem option. 这已经被证实是GNU Make中的一个问题,存在于启用了不区分大小写的文件系统选项的构建中。 It has also been fixed in the repository. 它也已在存储库中修复。

The solution is either to use a GNU Make build that doesn't have the case-insensitve filesystem option ( --enable-case-insensitive-file-system / HAVE_CASE_INSENSITIVE_FS ) enabled, or using the latest sources ( this revision or newer), where the issue is fixed. 解决方案是使用GNU Make构建,该构建没有启用case-insensitve文件系统选项(启用--enable-case-insensitive-file-system / HAVE_CASE_INSENSITIVE_FS ),或者使用最新源( 版本或更新版本),问题得到解决的地方。

Further references: 进一步参考:

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM