使用 MinGW 在 Windows 上编译小型 Gcc 项目
所以我用 C++ 编程已经快两年了,一直以来我很高兴使用具有可爱的项目设置和自动链接等功能的 IDE (VS)。 我总是远离任何需要我通过 makefile 进行编译的外部库,或者至少是那些适用于 Linux 环境/其他编译器的库。
无论如何,我现在想使用一个超级方便的实用程序(Bob Jenkins Perfect Minimal Hash)但它要求我通过 makefile 进行编译,不仅如此,还需要使用 g++ 编译器。
我继续获取 mingW32-make 实用程序,现在正在尝试让它工作。 我现在所处的位置:
- 成功安装 minGW
- 成功调用 make 实用程序
- 未能成功创建项目。
我得到的错误是:
C:\gen_progs\ph>mingw32-make
mingw32-make: *** 没有规则可制定 目标
lookupa.c',由
lookupa.o'需要。 停止。
和 makefile 本身:
CFLAGS = -O
.cc.o:
gcc $(CFLAGS) -c $<
O = lookupa.o recycle.o perfhex.o perfect.o
const64 : $(O)
gcc -o perfect $(O) -lm
# DEPENDENCIES
lookupa.o : lookupa.c standard.h lookupa.h
recycle.o : recycle.c standard.h recycle.h
perfhex.o : perfhex.c standard.h lookupa.h recycle.h perfect.h
perfect.o : perfect.c standard.h lookupa.h recycle.h perfect.h
现在这个错误似乎是合理的,至少从我对 makefile 的最低限度理解来看,我有所有引用的 .c、.h 文件,但是我没有 .o 文件,而且似乎没有任何文件有关如何制作这些的说明。 所以我的问题是:
我对 make 实用程序的调用是否错误? 或者我需要先编译目标文件? 或者...我需要在 make 文件中添加一些内容吗?
我再次拥有所有引用的 .c 和 .h 文件。
编辑:抱歉,我实际上丢失了该特定文件,它似乎已经在某处消失了。 但是,将其添加回来是我现在得到的错误:
c:\gen_progs\ph>mingw32-make
cc -O -c -o lookupa.o lookupa.c
process_begin: CreateProcess(NULL, cc -O -c -o lookupa.o lookupa.c, ...) failed.
make (e=2): The system cannot find the file specified.
mingw32-make: *** [lookupa.o] Error 2
so I've been programming in C++ for almost 2 years now, and the whole while I've had the pleasure of using an IDE (VS) with lovely project settings and automatic linking and the like. I've always stayed away from any external libraries which required me to compile via makefiles, or at least the ones which were meant for linux environments/other compilers.
Anyways I now want to use a super handy utility (Bob Jenkins Perfect Minimal Hash) but it requires me to compile via makefiles, not only that but using the g++ compiler.
I went ahead and got the mingW32-make utility and am now trying to get it to work. Where I'm at now:
- Succesfully installed minGW
- Succesfully called the make utility
- Failed to succesfully make the project.
The error I get is:
C:\gen_progs\ph>mingw32-make
mingw32-make: *** No rule to make
targetlookupa.c', needed by
lookupa.o'. Stop.
And the makefile itself:
CFLAGS = -O
.cc.o:
gcc $(CFLAGS) -c lt;
O = lookupa.o recycle.o perfhex.o perfect.o
const64 : $(O)
gcc -o perfect $(O) -lm
# DEPENDENCIES
lookupa.o : lookupa.c standard.h lookupa.h
recycle.o : recycle.c standard.h recycle.h
perfhex.o : perfhex.c standard.h lookupa.h recycle.h perfect.h
perfect.o : perfect.c standard.h lookupa.h recycle.h perfect.h
Now the error seems reasonable, at least from my minimal understanding of makefiles, I have all the referenced .c, .h files, however I have none of the .o files and there doesn't appear to be any instructions on how to make these. So my question/s are:
am I calling the make utility wrong? Or do I need to compile the object files first? Or... do I need to add something to the make file?
Again I have all the referenced .c and .h files.
Edit: Sorry about that I was actually missing that specific file it seems to have disapeared somewhere along the line. However, adding it back in this is the error I now get:
c:\gen_progs\ph>mingw32-make
cc -O -c -o lookupa.o lookupa.c
process_begin: CreateProcess(NULL, cc -O -c -o lookupa.o lookupa.c, ...) failed.
make (e=2): The system cannot find the file specified.
mingw32-make: *** [lookupa.o] Error 2
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
关于您的错误“process_begin:CreateProcess(NULL,cc -O -c -o Lookupa.o Lookupa.c,...)失败。”
这是因为 make 实用程序想要使用“cc”编译器来编译您的程序,但该编译器不是 Mingw 包的一部分。
解决方案:将“.cc.o:”更改为“.co:”。 这改变了隐式规则,该规则告诉 Make 在编译 .c 文件时使用什么编译器(下一行是 gcc)(原始行告诉它如何编译 .cc 文件)。
Regarding your error "process_begin: CreateProcess(NULL, cc -O -c -o lookupa.o lookupa.c, ...) failed."
This is because the make utility wants to use the "cc" compiler to compile your program, but that compiler is not part of the Mingw-package.
Solution: Change the ".cc.o:" to ".c.o:". This changes the implicit rule which tells Make what compiler to use (gcc on the next line) when compiling .c files (the original line tells it how to compile .cc files).
在命令行中输入
make -DCC=gcc
或将行CC=gcc
添加到 Makefile 的顶部也可以解决该问题。 Make 处理 C 源代码的内置规则都使用变量 CC 来命名 C 编译器,出于向后兼容性的原因,即使在 Gnu Make 中,它也默认为“cc”。看起来最初的 Makefile 作者试图通过提供编译
.cc
文件的自定义规则来解决该问题,但由于项目中没有.cc
文件,规则并没有被实际使用。恕我直言,为
CC
指定正确的值优于修复命名.c
文件的显式规则,因为 Makefile 通常更易于使用和维护,并且在最少的情况下是最可移植的。指定可能的信息。Saying either
make -DCC=gcc
at the command line or adding the lineCC=gcc
to the top of the Makefile would cure the issue as well. Make's built in rules for handling C source code all name the C compiler with the variable CC, which defaults to "cc" for reasons of backward compatibility even in Gnu Make.It looks like the original Makefile author tried to work around that problem by supplying a custom rule for compiling
.cc
files, but since there are no.cc
files in the project that rule was not actually used.Specifying the correct value for
CC
is superior to fixing the explicit rule to name.c
files IMHO because Makefiles are generally easier to use and maintain and are the most portable when the least possible information is specified.我不认为没有 .o 文件是问题所在。 Make 将从源文件(冒号右侧的文件)生成它们。
您眼前的问题似乎是 make 无法归档文件“lookupa.c”。 从您发布的规则来看,在我看来该文件应该与 makefile 位于同一目录中,但事实并非如此。 您需要弄清楚该文件在哪里以及如何将其获取到那里。
(出于某种原因,我脑海中浮现出 Wile E. Coyote 坐在他的电脑前,看到那个文件名,抬起头,然后被铁砧贴满的情景)。
I don't think not having .o files is the problem. Make will make them from the source files (the files to the right of the colon).
Your immediate problem seems to be that make can't file the file "lookupa.c". From the rules you posted, it looks to me like that file should be sitting in the same directory as the makefile, but it isn't. You need to figure out where that file is, and how to get it there.
(For some reason I have a mental image of Wile E. Coyote sitting at his computer, seeing that file name, looking up, and getting plastered with an anvil).