delorie.com/archives/browse.cgi   search  
Mail Archives: cygwin/2010/05/21/16:55:54

X-Recipient: archive-cygwin AT delorie DOT com
X-SWARE-Spam-Status: No, hits=4.0 required=5.0 tests=AWL,BAYES_00,FREEMAIL_ENVFROM_END_DIGIT,FREEMAIL_FROM,RCVD_IN_DNSWL_NONE,T_RP_MATCHES_RCVD
X-Spam-Check-By: sourceware.org
Message-ID: <SNT129-W79BE6AF2BB6FFFD328BBA87E40@phx.gbl>
From: bo yu <enviyub2 AT hotmail DOT com>
To: <tprince AT computer DOT org>, <marco_atzeri AT yahoo DOT it>
CC: <cygwin AT cygwin DOT com>
Subject: RE: How to compile Fortran 90 subroutine under CYGWIN
Date: Fri, 21 May 2010 20:55:41 +0000
In-Reply-To: <4BF6AF0F.90308@aol.com>
References: <SNT129-W2E72156B2337B784EB72687E40 AT phx DOT gbl>,<4BF6803B DOT 2060103 AT aol DOT com> <SNT129-W506D793A069A9C8255888187E40 AT phx DOT gbl>,<4BF6AF0F DOT 90308 AT aol DOT com>
MIME-Version: 1.0
X-IsSubscribed: yes
Mailing-List: contact cygwin-help AT cygwin DOT com; run by ezmlm
List-Id: <cygwin.cygwin.com>
List-Unsubscribe: <mailto:cygwin-unsubscribe-archive-cygwin=delorie DOT com AT cygwin DOT com>
List-Subscribe: <mailto:cygwin-subscribe AT cygwin DOT com>
List-Archive: <http://sourceware.org/ml/cygwin/>
List-Post: <mailto:cygwin AT cygwin DOT com>
List-Help: <mailto:cygwin-help AT cygwin DOT com>, <http://sourceware.org/ml/#faqs>
Sender: cygwin-owner AT cygwin DOT com
Mail-Followup-To: cygwin AT cygwin DOT com
Delivered-To: mailing list cygwin AT cygwin DOT com

Tim and Marco,
=20
Thanks for your replies and for your help. Under the ygwin, I can build cod=
es in .c and .f (Fortran-77) format, as shown in following Case 1. Now, I h=
ave codes in .f90 (Fortran-90) format and need a coupling.=20
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 g=
ot problem.=20

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 pr=
ograms 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
=20
=20

Case 1: Set g77 as fortran compiler, and gcc as C compiler, to compile C pr=
ograms and For77 programs
Fortran 77 program:   runslhg.f , intrface.f=20
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 =3D /bin/sh
CC =3D gcc
FC =3D g77
STRIP =3D strip
STD_FLAGS =3D -O3 -Wall -pedantic -ansi
FFLAGS =3D
LD_FLAGS =3D -Wl,--stack,8000000
STD_DEF =3D -D_WINDOWS_ -D_GCC_
STD_INC =3D -I.
STD_LIB =3D -lg2c -L/usr/lib -lm
PRJ_NAME =3D sloshDos
TARGETS =3D $(PRJ_NAME)
CFLAGS =3D $(STD_FLAGS) $(STD_DEF) $(STD_INC)
############################
# FILES
############################
H_SOURCES =3D slosh2.h \
            pack.h \
            myassert.h \
            myutil.h \
            savellx.h \
            complex.h \
            clock.h \
            tendian.h \
            tio3.h
C_OBJECTS =3D slosh2.o \
            pack.o \
            myassert.o \
            myutil.o \
            savellx.o \
            complex.o \
            clock.o \
            tendian.o \
            tio3.o
F_OBJECTS =3D runslhg.o \
            intrface.o
C_MAIN =3D 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=20
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_rea=
d'
runslhg.o:runslhg.f:,.text+0x6d>: undefined reference to '__gfortran_transf=
er_character'
runslhg.o:runslhg.f:,.text+0x7b>: undefined reference to '__gfortran_st_rea=
d_done'
Here is my 'makefile'
-----------------------------------------------
#!/bin/make
SHELL =3D /bin/sh
CC =3D gcc
FC =3D gfortran
STRIP =3D strip
STD_FLAGS =3D -O3 -Wall -pedantic -ansi
FFLAGS =3D
LD_FLAGS =3D -Wl,--stack,8000000
STD_DEF =3D -D_WINDOWS_ -D_GCC_
STD_INC =3D -I.
STD_LIB =3D -lg2c -L/usr/lib -lm
PRJ_NAME =3D sloshDos
TARGETS =3D $(PRJ_NAME)
CFLAGS =3D $(STD_FLAGS) $(STD_DEF) $(STD_INC)
############################
# FILES
############################
H_SOURCES =3D slosh2.h \
            pack.h \
            myassert.h \
            myutil.h \
            savellx.h \
            complex.h \
            clock.h \
            tendian.h \
            tio3.h
C_OBJECTS =3D slosh2.o \
            pack.o \
            myassert.o \
            myutil.o \
            savellx.o \
            complex.o \
            clock.o \
            tendian.o \
            tio3.o
F_OBJECTS =3D runslhg.o \
            intrface.o
C_MAIN =3D 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) $<
--------------------------------------------------------------
=20
=20
=20
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=20
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_rea=
d'
runslhg.o:runslhg.f:,.text+0x6d>: undefined reference to '__gfortran_transf=
er_character'
runslhg.o:runslhg.f:,.text+0x7b>: undefined reference to '__gfortran_st_rea=
d_done'
Here is my 'makefile'
-----------------------------------------------
#!/bin/make
SHELL =3D /bin/sh
CC =3D gcc
F77 =3D gfortran
STRIP =3D strip
STD_FLAGS =3D -O3 -Wall -pedantic -ansi
FFLAGS =3D
LD_FLAGS =3D -Wl,--stack,8000000
STD_DEF =3D -D_WINDOWS_ -D_GCC_
STD_INC =3D -I.
STD_LIB =3D -lg2c -L/usr/lib -lm
PRJ_NAME =3D sloshDos
TARGETS =3D $(PRJ_NAME)
CFLAGS =3D $(STD_FLAGS) $(STD_DEF) $(STD_INC)
############################
# FILES
############################
H_SOURCES =3D slosh2.h \
            pack.h \
            myassert.h \
            myutil.h \
            savellx.h \
            complex.h \
            clock.h \
            tendian.h \
            tio3.h
C_OBJECTS =3D slosh2.o \
            pack.o \
            myassert.o \
            myutil.o \
            savellx.o \
            complex.o \
            clock.o \
            tendian.o \
            tio3.o
F_OBJECTS =3D runslhg.o \
            intrface.o \
            swan_init.o \
            swan_loopstep.o=20
=20=20=20=20=20=20=20=20=20=20=20=20
C_MAIN =3D 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} $<=20
------------------------------------
=20
=20
As Tim and Marco already mentioned, gfortran is intended to be a full repla=
cement for g77, I will use gfortran as compile for all fortran program.=20
Now, my Questions are
(1) In case 2, I used gfortran as compiler to compile c codes and For77 cod=
es, 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 =91swan_init.o=92, but there is new=
 error message.
(3) Marco mentioned that 'during the linking you need to add the "-lgfortra=
nbegin -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 gfor=
tran 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. g7=
7 and gfortran can handle .c files automatically'. From the original makefi=
le, 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 Mak=
efile to use the Fortran compiler rather than gcc in makefile. Would you pl=
ease give me example?

I highly appreciate your time and your suggestion.=20
Thanks again,
=20
Thanks all and have a great weekend!
Bo
enviyub2 AT hotmail DOT com=20=09=09=20=09=20=20=20=09=09=20=20
_________________________________________________________________
The New Busy is not the old busy. Search, chat and e-mail from your inbox.
http://www.windowslive.com/campaign/thenewbusy?ocid=3DPID28326::T:WLMTAGL:O=
N: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

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019