I tested this issue this morning with the following simple program:
--- test_arg.f90 ---
! test_arg.f90 --
! Small test program: command-line arguments reachable
! via a DLL?
end program test_arg
and the module arg_mod:
--- arg.f90 ---
! arg.f90 --
! Print the command-line arguments
!dec$ attributes dllexport :: arguments
integer :: i, number
character(len=80) :: arg
!number = command_argument_count()
number = -1
write(*,'(a,i0)') 'Number of arguments: ', number
do i = 0,number
!call get_command_argument( i, arg )
write(*,'(a,i0,2a)') 'Command argument', i, ': - ', trim(arg)
end subroutine arguments
end module arg_mod
Compiler: gfortran, version 4.6.1 (version 4.6.2 gave the same result)
The gfortran commands to create were:
gfortran -o arg.dll arg.f90 -shared
gfortran -o test_arg test_arg.f90 arg.dll
Unfortunately, the answer I got was:
Number of arguments: -1
So, on Windows this will simply not work as we hoped!
I also tested this on Linux: same result (though there
I have a very old gfortran version - 4.1.2).
Using Intel Fortran 11.0 on Linux gives exactly the same result
too, but with the following message at link time:
/opt/intel/Compiler/11.0/081/lib/intel64/libimf.so: warning: warning:
feupdateenv is not implemented and will always fail
We can update configurable.f90 to take the new intrinsics into
account but we need to keep it in a static library.
On 2012-01-24 09:53, Arjen Markus wrote:
> Hello Alan,
> On Mon, 23 Jan 2012 11:45:22 -0800 (PST)
> "Alan W. Irwin" <irwin@...> wrote:
>> Hi Arjen:
>> I just spotted something of interest in the
>> gfortran-4.4.5 documentation
>> with respect to command-line parsing and the Fortran
>> 2003 standard.
>> To review the current status of Fortran command-line
>> bindings/f95/configurable.f90 uses iargc and getarg to
>> parse the
>> command line. These two routines are gfortran
>> extensions to be
>> backwards compatible with the g77 compiler and most
>> other Fortran
>> compilers. However, iargc and getarg apparently were
>> never part of
>> any standard, and the implementation sometimes sucks for
>> platforms. (As can be seen by the problems on Cygwin
>> with them, and
>> the fact that they only work in static libraries for the
>> So here is the key question:
>> Are COMMAND_ARGUMENT_COUNT and GET_COMMAND_ARGUMENT also
>> available on ifort
>> and also native Windows Fortran compilers?
> Yes, I think it is - I know for sure it is implemented
> in Ifort (from version 10.x onwards or at the very least
> 11.x). I would guess that any maintained compiler
> these routines.
>> If your tests show that is true, then I think we should
>> configurable.f90 to use those routines since they are in
>> the Fortran
>> 2003 standard (unlike iargc and getarg).
>> I think that "in the Fortran 2003 standard" argument is
>> already enough
>> motivation for making the switch. However, I am also
>> hoping the
>> standards-compliant COMMAND_ARGUMENT_COUNT and
>> routines will be properly implemented on Windows so it
>> will no longer
>> be necessary to always place configurable.f90 in a
>> static library on that
>> platform even when the rest of the Fortran libraries are
> I have seen some problems with the combination of programs
> and dynamic libraries on both Windows and Linux, but that
> may be due to the fact that the dynamic library in
> was dynamically loaded (that is: not as part of the link
> step, but by means of dlopen() and the like).
> I will experiment with this set-up to make sure there are
> no problems.
> (For compilers that do not implement the F2003 intrinsics
> there is actually a workaround possible that does not
> effect the others. It relies on a little used but
> standard feature of Fortran - the use and non-use of the
> external statement. But let us go that route only when
> it is clear that there are compilers around that do NOT
> implement these new intrinsics)
> DISCLAIMER: This message is intended exclusively for the addressee(s) and may contain confidential and privileged information. If you are not the intended recipient please notify the sender immediately and destroy this message. Unauthorized use, disclosure or copying of this message is strictly prohibited.
> The foundation 'Stichting Deltares', which has its seat at Delft, The Netherlands, Commercial Registration Number 41146461, is not liable in any way whatsoever for consequences and/or damages resulting from the improper, incomplete and untimely dispatch, receipt and/or content of this e-mail.
> Keep Your Developer Skills Current with LearnDevNow!
> The most comprehensive online learning library for Microsoft developers
> is just $99.99! Visual Studio, SharePoint, SQL - plus HTML5, CSS3, MVC3,
> Metro Style Apps, more. Free future releases when you subscribe now!
> Plplot-devel mailing list
DISCLAIMER: This message is intended exclusively for the addressee(s) and may contain confidential and privileged information. If you are not the intended recipient please notify the sender immediately and destroy this message. Unauthorized use, disclosure or copying of this message is strictly prohibited.
The foundation 'Stichting Deltares', which has its seat at Delft, The Netherlands, Commercial Registration Number 41146461, is not liable in any way whatsoever for consequences and/or damages resulting from the improper, incomplete and untimely dispatch, receipt and/or content of this e-mail.