Home > Archive > Fortran > December 2006 > Aargh - can't get makefile to work in gfortran under WindowsXP
You are viewing an archived Text-only version of the thread.
To view this thread in it's original format and/or if you want to reply to
this thread please [click here]
| Author |
Aargh - can't get makefile to work in gfortran under WindowsXP
|
|
| hywel.owen@talk21.com 2006-12-11, 7:12 pm |
| Can anyone help me with getting a makefile to work in gfortran please?
I used the binary installer at:
http://quatramaran.ens.fr/~coudert/...ran-windows.exe
and installed to C:\gfortran
I checked my paths are correct.
I have two tutorial files - main.f and printsomething.f:
printsomething.f:
C
C A SIMPLE SUBROUTINE
C
SUBROUTINE PRINTSOMETHING()
PRINT *, 'THE SUBROUTINE SAYS:'
PRINT *, 'HELLO HSL...'
RETURN
END SUBROUTINE
C
C END OF PRINTSOMETHING
C
main.f
C
C MAIN PART OF THE PROGRAM
C
PROGRAM HELLO
CALL PRINTSOMETHING()
END PROGRAM
C
C END OF THE MAIN PART
C
>From the DOS prompt, the following command works fine:
gfortran -o hello main.f printsomething.f
and I get the hello.exe file I am expecting.
But I can't get make to work at all. e.g. the following Makefile
doesn't work:
all: hello2.exe
hello2.exe: main.o printsomething.o
gfortran -o hello2.exe
What am I doing wrong? Is it:
a) make doesn't work in gfortran
b) I should be using the filename makefile or Makefile? (doesn't seem
to change things)
c) My makefile is wrong? (I can't find a template for this anywhere)
d) Something else....?
This is really frustrating me! Thanks,
Hywel
| |
| Sebastian Gallinat 2006-12-11, 7:12 pm |
| Hywel,
in some cases it is helpful to see the output of make in your command
prompt.
Your makefile has a rule to build the hello2 program from your two
object files. But I can't see any rule to build the object files by
themselves, analogous:
main.o: main.f
gfortran -c main.f -o main.o
and the same for the other file.
Hope, this helps,
Sebastian.
hywel.owen@talk21.com schrieb:
> Can anyone help me with getting a makefile to work in gfortran please?
>
> I used the binary installer at:
> http://quatramaran.ens.fr/~coudert/...ran-windows.exe
>
> and installed to C:\gfortran
>
> I checked my paths are correct.
>
> I have two tutorial files - main.f and printsomething.f:
>
> printsomething.f:
>
> C
> C A SIMPLE SUBROUTINE
> C
> SUBROUTINE PRINTSOMETHING()
> PRINT *, 'THE SUBROUTINE SAYS:'
> PRINT *, 'HELLO HSL...'
> RETURN
> END SUBROUTINE
> C
> C END OF PRINTSOMETHING
> C
>
> main.f
>
> C
> C MAIN PART OF THE PROGRAM
> C
> PROGRAM HELLO
> CALL PRINTSOMETHING()
> END PROGRAM
> C
> C END OF THE MAIN PART
> C
>
>
> gfortran -o hello main.f printsomething.f
>
> and I get the hello.exe file I am expecting.
>
> But I can't get make to work at all. e.g. the following Makefile
> doesn't work:
>
> all: hello2.exe
>
> hello2.exe: main.o printsomething.o
> gfortran -o hello2.exe
>
> What am I doing wrong? Is it:
> a) make doesn't work in gfortran
> b) I should be using the filename makefile or Makefile? (doesn't seem
> to change things)
> c) My makefile is wrong? (I can't find a template for this anywhere)
> d) Something else....?
>
> This is really frustrating me! Thanks,
>
> Hywel
>
| |
| olegus 2006-12-11, 7:12 pm |
|
> But I can't get make to work at all. e.g. the following Makefile
> doesn't work:
what exactly does not work? running make does not do anything, I
expect, because your Makefile is wrong.
>
> all: hello2.exe
>
> hello2.exe: main.o printsomething.o
> gfortran -o hello2.exe
>
> What am I doing wrong? Is it:
> a) make doesn't work in gfortran
Make has nothing to do with gfortran (except, possibly, recognizing .f
extension).
> b) I should be using the filename makefile or Makefile? (doesn't seem
> to change things)
> c) My makefile is wrong? (I can't find a template for this anywhere)
Try to delete hello2.exe before running make. If you allready do it
this way then you should read make manual or something.
> d) Something else....?
I paste my simple GNU Makefile here, but you should NOT copy/paste it,
because it will not work for you without small modifications.
#.SUFFIXES: *.f90
#FC=mpf90
#FCFLAGS=-I/opt/SUNWhpc/include -dalign -g
#LDFLAGS=-L/opt/SUNWhpc/lib -lmpi
FC=mpif90
all: Problem1
OBJS=config.o qsort.o utils.o
Problem1: $(OBJS) Problem1.f90
$(FC) $(FCFLAGS) -o $@ $^ $(LDFLAGS)
%.o: %.f90
$(FC) $(FCFLAGS) -c $^
clean:
rm -f Problem1
rm -f *.o *.mod
>
> This is really frustrating me! Thanks,
>
> Hywel
Find make tutorial and figure out how it works,
Oleg
| |
| hywel.owen@talk21.com 2006-12-11, 7:12 pm |
|
Sebastian Gallinat wrote:[color=darkred]
> Hywel,
>
> in some cases it is helpful to see the output of make in your command
> prompt.
>
> Your makefile has a rule to build the hello2 program from your two
> object files. But I can't see any rule to build the object files by
> themselves, analogous:
> main.o: main.f
> gfortran -c main.f -o main.o
> and the same for the other file.
>
> Hope, this helps,
>
> Sebastian.
>
>
> hywel.owen@talk21.com schrieb:
Thanks for the suggestion, but it doesn't work. The makefile now has:
all: hello2
main.o: main.f
gfortran -c main.f -o main.o
printsomething.o: printsomething.f
gfortran -c printsomething.f -o printsomething.o
hello2.exe: main.o printsomething.o
gfortran -o hello2.exe
no joy. Having looked at the manual for Gnu make, it seems to be
correct.
H
| |
| Steven G. Kargl 2006-12-11, 7:12 pm |
| In article <1165879040.817280.262120@n67g2000cwd.googlegroups.com>,
hywel.owen@talk21.com writes:
> Thanks for the suggestion, but it doesn't work. The makefile now has:
>
> all: hello2
>
> main.o: main.f
> gfortran -c main.f -o main.o
>
> printsomething.o: printsomething.f
> gfortran -c printsomething.f -o printsomething.o
>
> hello2.exe: main.o printsomething.o
> gfortran -o hello2.exe
gfortran -o hello2.exe main.o printsomething.o
Does this help?
--
Steve
http://troutmask.apl.washington.edu/~kargl/
| |
| hywel.owen@talk21.com 2006-12-11, 7:12 pm |
|
olegus wrote:
> what exactly does not work? running make does not do anything, I
> expect, because your Makefile is wrong.
That is exactly my question - what is wrong with my Makefile when using
the gfortran make utility, which is at: C:\gfortran\bin\make.exe
> Make has nothing to do with gfortran (except, possibly, recognizing .f
> extension).
I have no idea what you mean by that.
> Try to delete hello2.exe before running make.
No need, as there is no hello2.exe ever produced. I compiled no problem
from the command line to hello.exe
If you allready do it
> this way then you should read make manual or something.
Yes, I have RTFM (The Gnu make manual, anyway), and I thought I had a
correct Makefile. Obviously not though!
> I paste my simple GNU Makefile here, but you should NOT copy/paste it,
> because it will not work for you without small modifications.
>
> #.SUFFIXES: *.f90
>
> #FC=mpf90
> #FCFLAGS=-I/opt/SUNWhpc/include -dalign -g
> #LDFLAGS=-L/opt/SUNWhpc/lib -lmpi
>
> FC=mpif90
>
> all: Problem1
>
> OBJS=config.o qsort.o utils.o
>
> Problem1: $(OBJS) Problem1.f90
> $(FC) $(FCFLAGS) -o $@ $^ $(LDFLAGS)
>
> %.o: %.f90
> $(FC) $(FCFLAGS) -c $^
>
> clean:
> rm -f Problem1
> rm -f *.o *.mod
>
>
>
> Find make tutorial and figure out how it works,
> Oleg
Thanks for the obvious comment! I already tried that. I was looking to
see if someone had a template Makefile that matched some source, so I
could work from that. I adapted yours to give:
#.SUFFIXES: *.f
#FC=gfortran
FC=gfortran
all: hello
OBJS=main.o printsomething.o
hello: $(OBJS) hello.f
$(FC) $(FCFLAGS) -o $@ $^ $(LDFLAGS)
%.o: %.f
$(FC) $(FCFLAGS) -c $^
clean:
rm -f hello
rm -f *.o *.mod
--------------
but this doesn't work either. I guess that with no FCFLAGS or LDFLAGS
defined this is wrong? But it's commented out in your file, so it
should be ok? Unfortunately, gfortran doesn't have a Makefile tutorial
- at least, none that I can find.
Best,
H
| |
| hywel.owen@talk21.com 2006-12-11, 7:12 pm |
| Hi Steve,
Thanks for the 2nd reply - I'm pretty certain now that the make utility
that comes with GFortran doesn't work. I have a Makefile that works
under Linux, but not with this utility. I will find another utility
that does work - nmake or something like that..
Working Makefile (under Linux). Replace hello with hello.exe under
Windows and it still doesn't work.
all:
gfortran main.f printsomething.f -o hello
H
Steven G. Kargl wrote:
> In article <1165879040.817280.262120@n67g2000cwd.googlegroups.com>,
> hywel.owen@talk21.com writes:
>
> gfortran -o hello2.exe main.o printsomething.o
>
> Does this help?
>
> --
> Steve
> http://troutmask.apl.washington.edu/~kargl/
| |
| glen herrmannsfeldt 2006-12-11, 7:12 pm |
| hywel.owen@talk21.com wrote:
> That is exactly my question - what is wrong with my Makefile when using
> the gfortran make utility, which is at: C:\gfortran\bin\make.exe
Just to be sure, there needs to be a tab before the command
to be executed. Spaces look the same but don't work the same.
Some editors will even convert tabs to spaces for you.
-- glen
| |
| Craig Powers 2006-12-13, 4:18 pm |
| hywel.owen@talk21.com wrote:
>
> but this doesn't work either. I guess that with no FCFLAGS or LDFLAGS
> defined this is wrong?
No, if a variable is not defined then it will be replaced with nothing,
which will work.
| |
| Gene Wagenbreth 2006-12-13, 4:18 pm |
| I usually try make -n
That prints the commands that will be executed without actually executing them.
G
| |
|
| > Unfortunately, gfortran doesn't have a Makefile tutorial - at least,
> none that I can find.
The make utility that is distributed with the "standalone Windows"
installer for gfortran is_:
$ make.exe --version
GNU Make version 3.79.1, by Richard Stallman and Roland McGrath.
Built for i686-pc-msys
Copyright (C) 1988, 89, 90, 91, 92, 93, 94, 95, 96, 97, 98, 99, 2000
Free Software Foundation, Inc.
This is free software; see the source for copying conditions.
There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A
PARTICULAR PURPOSE.
Report bugs to <bug-make@gnu.org>.
It's the make utility packaged by MinGW/MSYS, and it works perfectly fine
for me: it is even used to build gfortran itself on my build system (I'm
the one building the MinGW packages you can find on the gfortran wiki).
--
FX
| |
|
| Moreover, I get the following:
$ cat main.f
subroutine foo
end subroutine foo
$ cat printsomething.f
SUBROUTINE PRINTSOMETHING()
PRINT *, 'THE SUBROUTINE SAYS:'
PRINT *, 'HELLO HSL...'
RETURN
END SUBROUTINE
$ cat hello.f
PROGRAM HELLO
CALL PRINTSOMETHING()
END PROGRAM
$ cat makefile
#.SUFFIXES: *.f
#FC=gfortran
FC=gfortran
all: hello
OBJS=main.o printsomething.o
hello: $(OBJS) hello.f
$(FC) $(FCFLAGS) -o $@ $^ $(LDFLAGS)
%.o: %.f
$(FC) $(FCFLAGS) -c $^
clean:
rm -f hello
rm -f *.o *.mod
$ make
gfortran -c main.f
gfortran -c printsomething.f
gfortran -o hello main.o printsomething.o hello.f
--
FX
| |
| hywel.owen@talk21.com 2006-12-13, 4:18 pm |
|
FX wrote:
> Moreover, I get the following:
>
> $ cat main.f
> subroutine foo
> end subroutine foo
>
> $ cat printsomething.f
> SUBROUTINE PRINTSOMETHING()
> PRINT *, 'THE SUBROUTINE SAYS:'
> PRINT *, 'HELLO HSL...'
> RETURN
> END SUBROUTINE
>
> $ cat hello.f
> PROGRAM HELLO
> CALL PRINTSOMETHING()
> END PROGRAM
>
> $ cat makefile
> #.SUFFIXES: *.f
>
> #FC=gfortran
>
> FC=gfortran
>
> all: hello
>
> OBJS=main.o printsomething.o
>
> hello: $(OBJS) hello.f
> $(FC) $(FCFLAGS) -o $@ $^ $(LDFLAGS)
>
> %.o: %.f
> $(FC) $(FCFLAGS) -c $^
>
> clean:
> rm -f hello
> rm -f *.o *.mod
>
> $ make
> gfortran -c main.f
> gfortran -c printsomething.f
> gfortran -o hello main.o printsomething.o hello.f
>
> --
> FX
Thanks very much for the reply. Now I know for sure that there is
something screwy with my system. I guess your utility usually works -
just not on my OS - I have Python 2.4 and 2.5, Ruby and a few other
things that have probably broken something on install.
Best,
H
| |
| hywel.owen@talk21.com 2006-12-13, 4:18 pm |
|
hywel.o...@talk21.com wrote:
> FX wrote:
>
> Thanks very much for the reply. Now I know for sure that there is
> something screwy with my system. I guess your utility usually works -
> just not on my OS - I have Python 2.4 and 2.5, Ruby and a few other
> things that have probably broken something on install.
>
> Best,
>
Ok, now I'm not so sure there is something wrong with my installation!
I have Windows XP SP2. I am told by my IT friends that the cat command
doesn't come as standard with XP. Does the make.exe program in gfortran
rely on being able to find cat? If so, that would explain the behaviour
I am getting?
For example, even when I run
make --version
(in a cmd.exe DOS-style prompt), I get nothing at all out of it.
The reason I ask all of this, rather than install cygwin or something
similar, is that I am trying to make a simple set of install
instructions for a set of people developing some mixed-language
simulations. They would like to use Fortran, so I'm trying to put
together a simple plain Windows install. gfortran is close, apart from
this make issue.
H
| |
| olegus 2006-12-13, 4:18 pm |
|
> Ok, now I'm not so sure there is something wrong with my installation!
>
> I have Windows XP SP2. I am told by my IT friends that the cat command
> doesn't come as standard with XP. Does the make.exe program in gfortran
> rely on being able to find cat? If so, that would explain the behaviour
> I am getting?
>
> For example, even when I run
> make --version
> (in a cmd.exe DOS-style prompt), I get nothing at all out of it.
No, I can't imagine why make would need cat.
Now I "speculate": probably there is problem with line breaks in unix
vs. windows :), so it considers makefile as one line. But --version
should work in this case.
Try mingw built make.
http://www.mingw.org/download.shtml
And you could try to remove all directories from the PATH variable
before running make or even boot in safe mode. (if I remember it
correctly "set PATH=" cleans PATH variable in cmd.exe)
>
> The reason I ask all of this, rather than install cygwin or something
> similar, is that I am trying to make a simple set of install
> instructions for a set of people developing some mixed-language
> simulations. They would like to use Fortran, so I'm trying to put
> together a simple plain Windows install. gfortran is close, apart from
> this make issue.
As last resort you could try MSYS which is small (several MB), but with
all tools needed.
Oleg
| |
| hywel.owen@talk21.com 2006-12-13, 4:18 pm |
|
olegus wrote:
> No, I can't imagine why make would need cat.
> Now I "speculate": probably there is problem with line breaks in unix
> vs. windows :), so it considers makefile as one line. But --version
> should work in this case.
>
> Try mingw built make.
> http://www.mingw.org/download.shtml
> And you could try to remove all directories from the PATH variable
> before running make or even boot in safe mode. (if I remember it
> correctly "set PATH=" cleans PATH variable in cmd.exe)
>
> As last resort you could try MSYS which is small (several MB), but with
> all tools needed.
>
Hi Oleg,
Thanks for the reply. This morning I tried:
http://unxutils.sourceforge.net/, and copied all the exec files into my
fortran folder
and got a running make, cat and ls etc. However, I still have no joy!
I get this output from make:
gfortran main.f printsomething.f -o hello.exe
gfortran: CreateProcess: No such file or directory
make: *** [all] Error 1
I give up! I'll do the compilation directly in Python. make is just
annoying.
H
| |
| olegus 2006-12-13, 4:18 pm |
|
> I get this output from make:
>
> gfortran main.f printsomething.f -o hello.exe
> gfortran: CreateProcess: No such file or directory
> make: *** [all] Error 1
Here make cannot find gfortran (or better say windows cannot find
gfortran). All you should do is change PATH variable (windows cmd.exe
uses this environment variable to search programs)
You have 2 possibilities
1) change PATH from cmd.exe with "set" or "setenv" command (not sure
which one works in cmd.exe). In this case it is only valid within
current cmd.exe and if open another cmd.exe it will have default value.
This default value comes from WinXP configuration and this is where
second possibility comes from.
2) change PATH in My Computer->Advanced->Environment variables. DO not
forget to run another instance of cmd.exe after that, because only new
cmd.exe instances grab new value of PATH.
You can see value of this variable by "echo %PATH%"
And change it with "setenv PATH C:\gfortran\bin;%PATH%"
In my last post I said to clean PATH because I thought some programs
which make may use are suddenly found from other installed packages and
it screws up "make" behaviour. This is often case in unix world, but
"make" is so simple that I believe it does not use anything else except
its binary code and windows libraries. So, change the PATH to what you
need, do not clean it :)
>
> I give up! I'll do the compilation directly in Python. make is just
> annoying.
Make is simple and always works. What you had before is broken make
with very odd behaviour. New make you installed seems to work, the only
thing wrong is PATH variable.
If you are puzzled with PATH, you can also try to set
FC=C:\gfortran\bin\gfortran in makefile, but it is not right solution,
becuase only works on your PC.
Do not give up yet ;)
Oleg
| |
| Kamaraju Kusumanchi 2006-12-13, 4:18 pm |
| > Hi Oleg,
>
> Thanks for the reply. This morning I tried:
> http://unxutils.sourceforge.net/, and copied all the exec files into my
> fortran folder
>
> and got a running make, cat and ls etc. However, I still have no joy!
>
> I get this output from make:
>
> gfortran main.f printsomething.f -o hello.exe
> gfortran: CreateProcess: No such file or directory
> make: *** [all] Error 1
>
Use the -d option of make to see what exactly it is doing. That error
could mean many things. The -d option works in Linux's (debian stable -
sarge) make. I have no idea if the windows' make comes with a -d option.
> I give up! I'll do the compilation directly in Python. make is just
> annoying.
>
This clearly tells me that you do not understand what make is for, what
python is for, what fortran is for! Make is not for compilation. Make is
a utility to maintain _groups_ of programs. It tells the program which
files need compiling, which do not, how they need to be compiled etc.,
The ones that are in need of compiling can then use a compiler to
compile the program...
Moreover, You can always do compilation using the fortran compiler
itself without bothering about make. I do not understand why python is
needed to _compile_ the program. However make will save you lot of
time/frustration in the future...
make can be used for a lot of other things besides this. For example, it
can be used to generate different resumes depending on the type of job
you are applying to. Ok, that is one wacko example but I think you get
the point.
Coming back to your question. You need to break down your problem into
smaller tasks and attack one-by-one. For example
1. can you compile a simple fortran program (everything in one file) on
the command line with the compiler?
2. can you compile a fortran program distributed among different files
3. can you write a makefile which echoes a specified string
4. can you write a makefile which will compile the program written in step1
5. can you write a makefile which will compile the program written in step2
Once you break it down like this, you will know where the problem is.
1 --- tells your compiler paths are set up properly
2 --- tells that your compilation and linking steps are correct
3 --- tells your make paths are set up properly
4 --- tells that make is able invoke the fortran compiler
5 --- tells that make is working for your situation...
Those are not hard and fast rules. But the idea is to attack it step by
step.
--
Kamaraju S Kusumanchi
http://www.people.cornell.edu/pages/kk288/
http://malayamaarutham.blogspot.com/
|
|
|
|
|