Tim and Marco,
 
Thanks for your replies and for your help. Under the ygwin, I can build codes 
in .c and .f (Fortran-77) format, as shown in following Case 1. Now, I have 
codes in .f90 (Fortran-90) format and need a coupling. 
My goal is to build all codes (.c, .f, .f90) togheter in cygwin. As Tim and 
Marco mentioned, gfortran can handle F90 and F77. Unfortunately, I still got 
problem. 

To explain the problem clearly, I have 3 different test cases, as shown in 
following:
Case 1: Set g77 as fortran compiler, and gcc as C compiler, to compile C 
programs and For77 programs, cgwin works
Case 2: Set gfortran as fortran compiler, and gcc as C compiler, to compile C 
programs and For77 programs, I got error message
Case 3: Set gfortran as fortran compiler, and gcc as C compiler, to compile C 
programs and For77 programs, I got error message
 
 

Case 1: Set g77 as fortran compiler, and gcc as C compiler, to compile C 
programs and For77 programs
Fortran 77 program:   runslhg.f , intrface.f 
C Program:            slosh2.c ,  cstart.c etc.
When I ran 'makefile' in cygwin, It works and I got the sloshDos.exe
Here is my 'makefile'
-----------------------------------------------
#!/bin/make
SHELL = /bin/sh
CC = gcc
FC = g77
STRIP = strip
STD_FLAGS = -O3 -Wall -pedantic -ansi
FFLAGS =
LD_FLAGS = -Wl,--stack,8000000
STD_DEF = -D_WINDOWS_ -D_GCC_
STD_INC = -I.
STD_LIB = -lg2c -L/usr/lib -lm
PRJ_NAME = sloshDos
TARGETS = $(PRJ_NAME)
CFLAGS = $(STD_FLAGS) $(STD_DEF) $(STD_INC)
############################
# FILES
############################
H_SOURCES = slosh2.h \
            pack.h \
            myassert.h \
            myutil.h \
            savellx.h \
            complex.h \
            clock.h \
            tendian.h \
            tio3.h
C_OBJECTS = slosh2.o \
            pack.o \
            myassert.o \
            myutil.o \
            savellx.o \
            complex.o \
            clock.o \
            tendian.o \
            tio3.o
F_OBJECTS = runslhg.o \
            intrface.o
C_MAIN = cstart.c
############################
# TARGETS
############################
all: $(TARGETS)
 @echo ""
$(PRJ_NAME): $(C_OBJECTS) $(F_OBJECTS) $(C_MAIN) $(LIB_DEPENDS) $(H_SOURCES)
 $(CC) $(C_MAIN) $(CFLAGS) $(LD_FLAGS) $(C_OBJECTS) $(F_OBJECTS) $(STD_LIB) -o 
$(PRJ_NAME)
 $(STRIP) -s $(PRJ_NAME).exe
install:
 cp *.exe ../../bin
clean:
 rm -f *.o *.bak *.BAK
############################
# SUFFIXES
############################
.c.o : $(H_SOURCES)
 $(CC) -c $(CFLAGS) $<
.f.o:
 ${FC} -c $(FFLAGS) $<
--------------------------------------------------------------

Case 2: Set gfortran as fortran compiler, and gcc as C compiler, to compile C 
programs and For77 programs
Fortran 77 program:   runslhg.f , intrface.f 
C Program:            slosh2.c ,  cstart.c etc.
When I ran 'makefile' in cygwin, I got error meassage here
runslhg.o:runslhg.f:,.text+0x4f>: undefined reference to '__gfortran_st_read'
runslhg.o:runslhg.f:,.text+0x6d>: undefined reference to 
'__gfortran_transfer_character'
runslhg.o:runslhg.f:,.text+0x7b>: undefined reference to 
'__gfortran_st_read_done'
Here is my 'makefile'
-----------------------------------------------
#!/bin/make
SHELL = /bin/sh
CC = gcc
FC = gfortran
STRIP = strip
STD_FLAGS = -O3 -Wall -pedantic -ansi
FFLAGS =
LD_FLAGS = -Wl,--stack,8000000
STD_DEF = -D_WINDOWS_ -D_GCC_
STD_INC = -I.
STD_LIB = -lg2c -L/usr/lib -lm
PRJ_NAME = sloshDos
TARGETS = $(PRJ_NAME)
CFLAGS = $(STD_FLAGS) $(STD_DEF) $(STD_INC)
############################
# FILES
############################
H_SOURCES = slosh2.h \
            pack.h \
            myassert.h \
            myutil.h \
            savellx.h \
            complex.h \
            clock.h \
            tendian.h \
            tio3.h
C_OBJECTS = slosh2.o \
            pack.o \
            myassert.o \
            myutil.o \
            savellx.o \
            complex.o \
            clock.o \
            tendian.o \
            tio3.o
F_OBJECTS = runslhg.o \
            intrface.o
C_MAIN = cstart.c
############################
# TARGETS
############################
all: $(TARGETS)
 @echo ""
$(PRJ_NAME): $(C_OBJECTS) $(F_OBJECTS) $(C_MAIN) $(LIB_DEPENDS) $(H_SOURCES)
 $(CC) $(C_MAIN) $(CFLAGS) $(LD_FLAGS) $(C_OBJECTS) $(F_OBJECTS) $(STD_LIB) -o 
$(PRJ_NAME)
 $(STRIP) -s $(PRJ_NAME).exe
install:
 cp *.exe ../../bin
clean:
 rm -f *.o *.bak *.BAK
############################
# SUFFIXES
############################
.c.o : $(H_SOURCES)
 $(CC) -c $(CFLAGS) $<
.f.o:
 ${FC} -c $(FFLAGS) $<
--------------------------------------------------------------
 
 
 
Case 3: Set gfortran as fortran compiler, and gcc as C compiler, to compile C 
programs, For77 programs and For90 programs
I change the .f90 to .f as Marco suggested
Fortran 77 program:   runslhg.f , intrface.f 
Fortran 90 program:   swan_init.f ,  swan_loopstep.f
C Program:            slosh2.c ,  cstart.c etc.
When I ran 'makefile' in cygwin, I got error meassage here
runslhg.o:runslhg.f:,.text+0x4f>: undefined reference to '__gfortran_st_read'
runslhg.o:runslhg.f:,.text+0x6d>: undefined reference to 
'__gfortran_transfer_character'
runslhg.o:runslhg.f:,.text+0x7b>: undefined reference to 
'__gfortran_st_read_done'
Here is my 'makefile'
-----------------------------------------------
#!/bin/make
SHELL = /bin/sh
CC = gcc
F77 = gfortran
STRIP = strip
STD_FLAGS = -O3 -Wall -pedantic -ansi
FFLAGS =
LD_FLAGS = -Wl,--stack,8000000
STD_DEF = -D_WINDOWS_ -D_GCC_
STD_INC = -I.
STD_LIB = -lg2c -L/usr/lib -lm
PRJ_NAME = sloshDos
TARGETS = $(PRJ_NAME)
CFLAGS = $(STD_FLAGS) $(STD_DEF) $(STD_INC)
############################
# FILES
############################
H_SOURCES = slosh2.h \
            pack.h \
            myassert.h \
            myutil.h \
            savellx.h \
            complex.h \
            clock.h \
            tendian.h \
            tio3.h
C_OBJECTS = slosh2.o \
            pack.o \
            myassert.o \
            myutil.o \
            savellx.o \
            complex.o \
            clock.o \
            tendian.o \
            tio3.o
F_OBJECTS = runslhg.o \
            intrface.o \
            swan_init.o \
            swan_loopstep.o 
            
C_MAIN = cstart.c
############################
# TARGETS
############################
all: $(TARGETS)
 @echo ""
$(PRJ_NAME): $(C_OBJECTS) $(F_OBJECTS) $(C_MAIN) $(LIB_DEPENDS) $(H_SOURCES)
 $(CC) $(C_MAIN) $(CFLAGS) $(LD_FLAGS) $(C_OBJECTS) $(F_OBJECTS) $(STD_LIB) -o 
$(PRJ_NAME)
 $(STRIP) -s $(PRJ_NAME).exe
install:
 cp *.exe ../../bin
clean:
 rm -f *.o *.bak *.BAK
############################
# SUFFIXES
############################
.c.o : $(H_SOURCES)
 $(CC) -c $(CFLAGS) $<
.f.o:
 ${F77} -c ${FFLAGS} $< 
------------------------------------
 
 
As Tim and Marco already mentioned, gfortran is intended to be a full 
replacement for g77, I will use gfortran as compile for all fortran program. 
Now, my Questions are
(1) In case 2, I used gfortran as compiler to compile c codes and For77 codes, 
why I got error?
(2) Following Marco's suggestion, I rename .f90 to .f in Case 3, fixed the 
problem of  '*** No rule to make target ‘swan_init.o’, but there is new error 
message.
(3) Marco mentioned that 'during the linking you need to add the 
"-lgfortranbegin -lgfortran"'. I am new to 'makefile' and gnu, where should I 
add in 'makefile?
(4) Fortran-77 is fix format while Fortran 90 is free format. If I set gfortran 
as my compiler, should I change all fortran extension name to be .f or .for?
(5) Tim mentioned that 'You should persuade the Makefile to use the Fortran 
compiler rather than gcc for compiling and linking Fortran source code. g77 and 
gfortran can handle .c files automatically'. From the original makefile, which 
works well as shown in Case 1, gcc will compile C program and g77 will compile 
fortran program. I really do not know how to persuade the Makefile to use the 
Fortran compiler rather than gcc in makefile. Would you please give me example?

I highly appreciate your time and your suggestion. 
Thanks again,
 
Thanks all and have a great weekend!
Bo
enviy...@hotmail.com                                      
_________________________________________________________________
The New Busy is not the old busy. Search, chat and e-mail from your inbox.
http://www.windowslive.com/campaign/thenewbusy?ocid=PID28326::T:WLMTAGL:ON:WL:en-US:WM_HMP:042010_3

--
Problem reports:       http://cygwin.com/problems.html
FAQ:                   http://cygwin.com/faq/
Documentation:         http://cygwin.com/docs.html
Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple

Reply via email to