开发者

How can I ctreate a simple makefile for minGW + gfortran

I am absolut开发者_运维知识库ely new in gfortran+minGW. I need to create makefile. When I run

$ gfortran  -c q.f

All is ok! But how can I run makefile like this?

CC = gfortran 
q.o :  q.f 
        $(CC) -c q2.o q2.f

I receive error “CC: command not found”.

(OS – Win 7 (64)) Tanks!!!


It kind of looks like you're trying to run the makefile as a regular script. Try

 $ make

or

 $ make -f mymakefilename

if you named the file something other than "makefile" or "Makefile".

You can potentially just execute the makefile, but if so you need a "shebang" line, something like

 #!/usr/bin/make

at the top of the file, but frankly hardly anyone uses that option. Just use the make(1) command.

Update

It's because they're in the wrong order. Makefiles process (by default) the first target in the file. When you run make it sees the rule to make, q.o from q.f, it compiles it, and says, "Okay, I'm done."

If you put the q.exe target first, it says "Hmmm, I want to build q.exe and to do that I need a q.o. Do I have a q.o? No? Okay, hen I'll build a q.o. I have a rule for that -- I can build a q.o from q.f. okay, that's done. Now can I build q.exe? Oh, yes, I can. I'll build q.exe. Anything? Nope, I'm done."

If you were to use the commend

  $ make q.exe

then you'd explicitly tell make to make q.exe, which would cause the same thing to happen, but better you should reorder your makefile and get used to the way they work.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜