Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Public/Private or gfortran problem?

1 view
Skip to first unread message

Chris Bradley

unread,
Dec 22, 2008, 8:21:40 AM12/22/08
to
Hi all,
I have a code that fails to compile/link properly with gfortran. Before
I submit a bug report I like to have the newsgroups advice as to whether
this is indeed a bug or simply me misunderstanding the standard.

If I have the following

$cat test3.f90
MODULE TEST3

PRIVATE

CHARACTER(LEN=80) :: TESTCHAR
INTEGER :: TESTINT
REAL :: TESTREAL

COMMON /TESTCOMMON1/ TESTCHAR
COMMON /TESTCOMMON2/ TESTINT
COMMON /TESTCOMMON3/ TESTREAL

END MODULE TEST3

$cat test2.f90
MODULE TEST2

USE TEST3

PRIVATE

CHARACTER(LEN=80) :: TESTCHAR
INTEGER :: TESTINT
REAL :: TESTREAL

COMMON /TESTCOMMON1/ TESTCHAR
COMMON /TESTCOMMON2/ TESTINT
COMMON /TESTCOMMON3/ TESTREAL

PUBLIC TESTCHAR

END MODULE TEST2

$cat test1.f90
PROGRAM TEST1

USE TEST2

WRITE(*,*) TESTCHAR

END PROGRAM TEST1

then when I compile it with gfortran it get the following problem

$gfortran -o test3.o -g -c test3.f90
$gfortran -o test2.o -g -c test2.f90
$gfortran -o test1.o -g -c test1.f90
$gfortran -o test1 -g test1.o test2.o test3.o
test1.o: In function `test1':
/data/test1.f90:6: undefined reference to `__test2_MOD_testchar'
collect2: ld returned 1 exit status
make: *** [test1] Error 1
$ gfortran -v
Using built-in specs.
Target: x86_64-redhat-linux
Configured with: ../configure --prefix=/usr --mandir=/usr/share/man
--infodir=/usr/share/info
--with-bugurl=http://bugzilla.redhat.com/bugzilla --enable-bootstrap
--enable-shared --enable-threads=posix --enable-checking=release
--with-system-zlib --enable-__cxa_atexit --disable-libunwind-exceptions
--enable-languages=c,c++,objc,obj-c++,java,fortran,ada
--enable-java-awt=gtk --disable-dssi --enable-plugin
--with-java-home=/usr/lib/jvm/java-1.5.0-gcj-1.5.0.0/jre
--enable-libgcj-multifile --enable-java-maintainer-mode
--with-ecj-jar=/usr/share/java/eclipse-ecj.jar
--disable-libjava-multilib --with-cpu=generic --build=x86_64-redhat-linux
Thread model: posix
gcc version 4.3.2 20081105 (Red Hat 4.3.2-7) (GCC)

If I comment out the USE TEST3 line in test2.f90 then all is fine. The
test code also compiles and links without any problems with the intel
and IBM compilers. Given that everything is private in TEST3 then my
understanding is that it shouldn't matter if TEST2 uses it or not? Is
this a compiler bug or my misunderstanding of the use of COMMON blocks
inside PRIVATE modules?

Thanks in advance
Chris

GaryScott

unread,
Dec 22, 2008, 11:11:07 AM12/22/08
to

CVF 6.6c likes it with F95 standards compliance checking applied. Not
proof that it's ok, but looks ok to me.

GaryScott

unread,
Dec 22, 2008, 11:29:03 AM12/22/08
to
On Dec 22, 7:21 am, Chris Bradley <chris.brad...@dpag.ox.ac.uk> wrote:

P.S. I think you have to interpret the COMMON definition as equivalent
to a public declaration for those items in COMMON.

michael...@compuserve.com

unread,
Dec 22, 2008, 12:10:23 PM12/22/08
to
> to a public declaration for those items in COMMON.- Hide quoted text -
>
> - Show quoted text -
No, that is not quite the case: variable names in a common block in a
module may be declared to have the private attribute, however, this
does not prevent
associated variables being declared elsewhere through other common
statements ("Fortran 95/2003 Explained", Section 20.2.3). The code in
question looks fine to me.

Regards,

Mike Metcalf


GaryScott

unread,
Dec 22, 2008, 1:44:12 PM12/22/08
to

Thanks, yes, I thought that was incorrect shortly after posting.

> module may be declared to have the private attribute, however, this
> does not prevent
> associated variables being declared elsewhere through other common
> statements ("Fortran 95/2003 Explained", Section 20.2.3). The code in
> question looks fine to me.
>
> Regards,
>

> Mike Metcalf- Hide quoted text -

paul.rich...@gmail.com

unread,
Dec 22, 2008, 5:12:49 PM12/22/08
to
Regrettably, this is a regression, since it worked OK in
gfortran-4.1.2. I will post it in Bugzilla tomorrow, if you do not
beat me to it.

Cheers and thanks for the report.

Paul

paul.rich...@gmail.com

unread,
Dec 28, 2008, 6:09:03 PM12/28/08
to
On Dec 22, 11:12 pm, paul.richard.tho...@gmail.com wrote:
> Regrettably, this is a regression, since it worked OK in
> gfortran-4.1.2. I will post it in Bugzilla tomorrow, if you do not
> beat me to it.

Posted as PR38657.

Thanks for the report.

Paul

Chris Bradley

unread,
Dec 30, 2008, 6:26:26 AM12/30/08
to
Hi all,
thanks for the comments and thanks to Paul for submitting the bug for me
(I've been away from the computer).

Best wishes
Chris

0 new messages