Re: Allocatable arrays and shared libraries: help needed
- From: sgiannerini@xxxxxxxxx
- Date: Wed, 5 Dec 2007 08:02:31 -0800 (PST)
Dear Tobias,
many thanks for your suggestion, adding an explicit interface solves
the problem.
I did not mention that I had tried with the EXTERNAL without success
before I posted.
Just for completeness, I am creating a shared library to be used
inside another environment (the software R) so that each subroutine of
the library can call each other and can be called from R, I have no
main programs. I may try building a module which is something I have
always been using but not for shared objects, I may come back in case
of problems, hopefully not ;) . In this way if I am correct I may
avoid specifying the INTERFACE for every subroutine.
I see you are involved into gfortran development so this may be of
interest to you as well:
I have tested the simple routine I posted before both under win and
Linux and found syntax differences when linking to shared objects:
LINUX: ***************************************************************
gfortran-4.3 try.f90 -s -shared -Wall -fPIC -fbounds-check -olibtry.a
gfortran-4.3 provaci.f90 -L/PATH TO libtry.a/ -ltry -oprovaci.exe
gfortran --version
GNU Fortran (GCC) 4.3.0 20070509 (experimental) (SUSE Linux)
Copyright (C) 2007 Free Software Foundation, Inc.
Windows:
***************************************************************
gfortran try.f90 -s -shared -Wall -fbounds-check -otry.dll
gfortran provaci.f90 -L/PATH TO try.dll/ -ltry -oprovaci.exe
gfortran --version
GNU Fortran (GCC) 4.2.1-sjlj (mingw32-2)
Copyright (C) 2007 Free Software Foundation, Inc.
In brief, in order to be able to use the -lLIBRARYNAME command in
linux you have to name the library as libLIBRARYNAME.a whereas in Win
you have to specify it as LIBRARYNAME.dll.
I have to say that I had to struggle a bit through the gcc docs to
find it out.
Is this difference expected?
Thank you very much again for your concern.
Simone
On Dec 4, 8:47 pm, fj <francois.j...@xxxxxxx> wrote:
On 3 déc, 20:09, Tobias Burnus <bur...@xxxxxxxx> wrote:
On Dec 3, 6:36 pm, sgianner...@xxxxxxxxx wrote:> I have a problem regarding dummy allocatable array past as arguments
of a subroutine in a shared library:
The issue boils down to this simple program that allocates a matrix
and prints its content:
PROGRAM PROVACI[...]
CONTAINS
SUBROUTINE TRY(ROW,COL,T)
[...]
Now remove the subroutine TRY, put it in a separate file
Note: You need to give an explicit interface for the subroutine TRY. A
simple
CALL TRY (...)
or
EXTERNAL TRY
CALL TRY (...)
won't work.
Can you add:
INTERFACE
SUBROUTINE TRY(ROW,COL,T)
integer,INTENT(IN):: ROW,COL
integer,allocatable,INTENT(OUT):: T(:,:)
END SUBROUTINE TRY
END INTERFACE
to "PROGRAM PROVACI" and try again? (Instead of "INTERFACE", you can
also put "TRY" into a module and use the module.)
Tobias
I would like to precise that allocating an argument in such a way is
not F90 nor F95 (but it is OK in F95+ and F2003). Fortunately, most of
F95 compilers support that extension now !
I was very disappointed by my first experience with F90, about 10
years ago, when I tried a similar programming (and without forgetting
the mandatory interface). I got a "segmentation fault" in the main
program at the write statement :-( The only way to overcome the
problem was to replace ALLOCATABLE by POINTER.
.
- Follow-Ups:
- Re: Allocatable arrays and shared libraries: help needed
- From: Janne Blomqvist
- Re: Allocatable arrays and shared libraries: help needed
- From: James Van Buskirk
- Re: Allocatable arrays and shared libraries: help needed
- References:
- Allocatable arrays and shared libraries: help needed
- From: sgiannerini
- Re: Allocatable arrays and shared libraries: help needed
- From: Tobias Burnus
- Re: Allocatable arrays and shared libraries: help needed
- From: fj
- Allocatable arrays and shared libraries: help needed
- Prev by Date: Re: Does g77 allows #include directives in FORTRAN 77 applications
- Next by Date: Re: Password security
- Previous by thread: Re: Allocatable arrays and shared libraries: help needed
- Next by thread: Re: Allocatable arrays and shared libraries: help needed
- Index(es):
Relevant Pages
|