From: LQH on 29 Jan 2010 14:17 Hi friends, I have a question relating to the Makefile of Fortran. I really appreciate if you friend willing to help me to solve it. I have a very simple program include [main.f90] and [commons.f90] as described above. I am trying to compose a typical makefile to compile it. However, it does not work because of error associated with compiling module (I guess so). Thank you for reading my problem. LQH HPC Command Windows ------------------------------------------------------------ Fortran diagnostic messages: program name(main) jwd1370i-s "main.f90", line 2: Module 'commons' is not available. jwd2006i-i "main.f90", line 3: 'n' is declared but never referenced. make: *** [main.o] Error 1 Makefile ------------------------------------------------------------ TARGET = ../exe FC = f90 FFLAGS = OBJS = \ commons.o \ main.o ..f90.o: ${FC} -c ${FFLAGS} ${OBJS} $< -o $@ main.o : commons.o ..SUFFIXES : ..SUFFIXES : .o .f90 ${TARGET} : ${OBJS} ${FC} ${FFLAGS} ${OBJS} -o $@ commons.f90 ------------------------------------------------------------ MODULE commons integer,parameter:: n=1 END main.f90 ------------------------------------------------------------ use commons write(*,*)n END
From: dpb on 29 Jan 2010 14:37 LQH wrote: > Hi friends, > > I have a question relating to the Makefile of Fortran. I really > appreciate if you friend willing to help me to solve it. > > I have a very simple program include [main.f90] and [commons.f90] as > described above. I am trying to compose a typical makefile to compile > it. > > However, it does not work because of error associated with compiling > module (I guess so). .... > jwd1370i-s "main.f90", line 2: Module 'commons' is not available. .... OK, the error is exactly what it says... USE requires the module be compiled prior to the module/routine that attempts to USE it. It is _NOT_ like an INCLUDE in that regard. > .f90.o: > ${FC} -c ${FFLAGS} ${OBJS} $< -o $@ > main.o : commons.o So, you've told it to build main before commons--swap the order and should be good to go. --
From: Ron Shepard on 29 Jan 2010 15:22 In article <cfd4dd2d-9f17-4322-ba9c-90c2c6ecf35d(a)w27g2000pre.googlegroups.com>, LQH <luuquanghung(a)gmail.com> wrote: > TARGET = ../exe > FC = f90 > FFLAGS = > OBJS = \ > commons.o \ > main.o > .f90.o: > ${FC} -c ${FFLAGS} ${OBJS} $< -o $@ > main.o : commons.o > .SUFFIXES : > .SUFFIXES : .o .f90 > ${TARGET} : ${OBJS} > ${FC} ${FFLAGS} ${OBJS} -o $@ It is difficult to debug makefiles in newsgroups because of the nonprinting characters. However, I think the problem is the .f90.o implicit rule. This line should begin with a tab character, and it incorrectly references ${OBS}. I think it should be something like <tab>${FC} -c ${FFLAGS} -o $@ $< Similarly, the last line should be something like <tab>${FC} ${FFLAGS} -o $@ $< When you execute the make command, the commons.f90 file should compile first, and then the main.f90 file should be compiled, then the two object files should be loaded to create the ../exe file. Afterwards, there should be commons.o, main.o, and commons.mod files in the directory. $.02 -Ron Shepard
From: rudra on 30 Jan 2010 05:36 On Jan 29, 8:17 pm, LQH <luuquangh...(a)gmail.com> wrote: > Hi friends, > > I have a question relating to the Makefile of Fortran. I really > appreciate if you friend willing to help me to solve it. > > I have a very simple program include [main.f90] and [commons.f90] as > described above. I am trying to compose a typical makefile to compile > it. > > However, it does not work because of error associated with compiling > module (I guess so). > > Thank you for reading my problem. > > LQH > > HPC Command Windows > ------------------------------------------------------------ > > Fortran diagnostic messages: program name(main) > jwd1370i-s "main.f90", line 2: Module 'commons' is not available. > jwd2006i-i "main.f90", line 3: 'n' is declared but never > referenced. > make: *** [main.o] Error 1 > > Makefile ------------------------------------------------------------ > > TARGET = ../exe > FC = f90 > FFLAGS = > OBJS = \ > commons.o \ > main.o > .f90.o: > ${FC} -c ${FFLAGS} ${OBJS} $< -o $@ > main.o : commons.o > .SUFFIXES : > .SUFFIXES : .o .f90 > ${TARGET} : ${OBJS} > ${FC} ${FFLAGS} ${OBJS} -o $@ > > commons.f90 > ------------------------------------------------------------ > > MODULE commons > integer,parameter:: n=1 > END > > main.f90 ------------------------------------------------------------ > > use commons > write(*,*)n > > END Your best bet is use commons.o dependency on main.i.e. your makefile should be like: main.o:main.f90 commons.o <tab>$(FC) -c main.f90 commons.o:commons.f90 <tab>$(FC) -c commons.f90 in this way, make knows to "make" commons before main and it will do that exactly.
From: Richard Maine on 30 Jan 2010 12:03
rudra <bnrj.rudra(a)gmail.com> wrote: > On Jan 29, 8:17 pm, LQH <luuquangh...(a)gmail.com> wrote: ..... > > main.o : commons.o .... > Your best bet is use commons.o dependency on main He already does (though that description sounds backwards - it is main.o that has a dependency on commons.o) . See the above-quoted line. Ron's explanation seems to the point. -- Richard Maine | Good judgment comes from experience; email: last name at domain . net | experience comes from bad judgment. domain: summertriangle | -- Mark Twain |