From: Alan W. I. <ir...@be...> - 2005-11-23 10:46:16
|
On 2005-11-23 08:40+0100 Arjen Markus wrote: > Hello Alan, > > here are the results of my experiment: > > main program (tstarg.f): > > program tstarg > call chkargs > end > > subroutine (chkargs.f): > > subroutine chkargs > integer i > integer iargc > external iargc, getarg > character*20 arg > > write(*,*) 'Number arguments:', iargc() > do i = 0,5 > call getarg(i,arg) > write(*,*) i, arg > enddo > return > end > > This works as expected if I do: > > g77 -o tstarg tstarg.f chkargs.f > ./tstarg a b c > > Result: > Number arguments: 3 > 0./tstarg.exe > 1a > 2b > 3c > 4 > 5 > > This gives a coredump or rather an error message with the > invitation to send an email to MicroSoft about the problem, > when I put the subroutine in a shared library: > > HP_Eigenaar@souterrain > /cygdrive/c/arjen/plplot/plplot-5.5.3/examples/f90 > $ g77 -o chkargs.so -shared chkargs.f -fPIC > chkargs.f:0: warning: -fPIC ignored for target (all code is position > independent > ) > > HP_Eigenaar@souterrain > /cygdrive/c/arjen/plplot/plplot-5.5.3/examples/f90 > $ g77 -o tstarg tstarg.f chkargs.so -fPIC > tstarg.f:0: warning: -fPIC ignored for target (all code is position > independent) > > > HP_Eigenaar@souterrain > /cygdrive/c/arjen/plplot/plplot-5.5.3/examples/f90 > $ ./tstarg a b c > > <<Error message>> > > HP_Eigenaar@souterrain > /cygdrive/c/arjen/plplot/plplot-5.5.3/examples/f90 > $ > > The -fPIC is not relevant on the Cygwin platform it seems, but to my > surprise, the program also fails when I pass the iargc and getarg > routines as arguments (I thought I might be able to bypass the snake pit > of memory issues that way). I tried several other variations, but the > result was the same: only when I use iargc() and getarg() from a > static library will the program work as expected. > Hi Arjen, Thanks for your experiments so far. However, I am not sure your above compile step is actually going to create a shared library for Cygwin. From your previous shared library compile runs for the PLplot build, here is the equivalent of how libtool would do it on Cygwin (assuming you ignore -fPIC which I agree with you seems irrelevant from the above messages). #Create compiled object. This step appears to be the same as required for #the static case on Cygwin. g77 chkargs.f -o chkargs.o #Create shared library from that compiled object g77 -shared chkargs.o -o cygplplotf77d-9.dll \ -Wl,--enable-auto-image-base \ -Wl,--out-implib,libplplotf77d.dll.a #Create main programme which uses the shared library g77 tstarg.f -o tstarg libplplotf77d.dll.a I don't know the purpose of creating both the cyg*-9.dll form and lib*.dll.a form of the shared library, but I notice lots of Cygwin shared libraries seem to be organized that way. Could you try this 3-part shared build method, please? If there is some obvious improvement to this scheme that you prefer, please let me know your exact 3-part shared build steps so that I can report them to the Cygwin list along with the rest of the bug report (see below). Here are some more semi-random experiments I suggest you try. Most of these experiments assume there is some sort of error that exists for both static and shared linking, but which has no visible symptoms (by accident) for static linking. Did you try dropping the external statement? It is not needed on Linux, and in fact I don't see the point of it at all. Would you use external for any other library function such as cos? It might cause an error on Cygwin (which is only visible for shared linking). I would also drop the type statement for iargc since that is an intrinsic function. The Cygwin fortran library may have the wrong intrinsic type for iargc implemented by mistake so I suggest your best bet is to let it figure out the intrinsic type for iargc itself rather than forcing a type that may not agree with the implementation. Again, I am going by the way an invocation of the cos function should be handled. What happens if you only have the iargc call and comment out the getchar call and vice versa? I would like to know which fails or whether they both fail. What happens if you comment out the getchar call and replace the iargc call by calculating cos(1.0)? The linking and memory issues should be similar to iargc and getarg so if cos works and iargc and/or getarg do not, then that eliminates some possible explanations for the problem. Once you tell me the exact 3-part commands you used to compile and link the shared library and compile and link the main routine, and also once you have the results of the second round of simple experiments and exact error messages, then I would be happy to write up the bug report for the Cygwin list unless you want to do that yourself. I expect once they get such a detailed bug report with a simple example where they can verify the error for themselves, they will give us some quick action. Alan __________________________ Alan W. Irwin email: ir...@be... phone: 250-727-2902 Astronomical research affiliation with Department of Physics and Astronomy, University of Victoria (astrowww.phys.uvic.ca). Programming affiliations with the FreeEOS equation-of-state implementation for stellar interiors (freeeos.sf.net); PLplot scientific plotting software package (plplot.org); the Yorick front-end to PLplot (yplot.sf.net); the Loads of Linux Links project (loll.sf.net); and the Linux Brochure Project (lbproject.sf.net). __________________________ Linux-powered Science __________________________ |