使用MinGW在Windows上编译Small Gcc项目 [英] Compiling Small Gcc Project on Windows Using MinGW

查看:145
本文介绍了使用MinGW在Windows上编译Small Gcc项目的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以我从事C ++编程已经快两年了,整个过程中,我一直很高兴地使用带有可爱的项目设置和自动链接等功能的IDE(VS).我始终远离需要我通过makefile进行编译的任何外部库,或者至少是那些用于linux环境/其他编译器的库.

无论如何,我现在都想使用超级方便的实用程序( Bob Jenkins完美的最小哈希),但这不仅要求我通过makefile进行编译,而且还需要使用g ++编译器进行编译.

我继续前进,得到了mingW32-make实用程序,现在正试图使其运行.我现在在哪里:

  • 成功安装了minGW
  • 成功调用了make实用程序
  • 无法成功创建项目.

我得到的错误是:

C:\ gen_progs \ ph> mingw32-make

mingw32-make:***没有规则 目标lookupa.c', needed by 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

解决方案

关于您的错误"process_begin:CreateProcess(NULL,cc -O -c -o lookupa.o lookupa.c,...)失败."

这是因为make实用程序想要使用"cc"编译器来编译程序,但是该编译器不是Mingw软件包的一部分.

解决方案:将".cc.o:"更改为".c.o:".这将更改隐式规则,该隐式规则告诉Make编译.c文件时要使用哪个编译器(下一行是gcc)(原始行告诉它如何编译.cc文件).

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 target lookupa.c', needed by lookupa.o'. Stop.

And the makefile itself:

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

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

解决方案

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).

这篇关于使用MinGW在Windows上编译Small Gcc项目的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆