On Sat, Jul 30, 2011 at 1:42 PM, Rajeev Singh <rajs2...@gmail.com> wrote:
> Hi, > > I have a script (say a.py) which uses a function written in fortran 90. > Within the script I give the command to compile using - > > os.system('f2py -c PD_evolve.f90 -m PD_evolve') > > It works fine on my computer if I run the script using - > > python a.py > > However it doesn't work if I use - > > sage -python a.py > > and gives an error while compiling. The last lines of error message are - > > /usr/bin/gfortran -Wall > /tmp/tmpBTbBKB/tmp/tmpBTbBKB/src.linux-i686-2.6/PD_evolvemodule.o > /tmp/tmpBTbBKB/tmp/tmpBTbBKB/src.linux-i686-2.6/fortranobject.o > /tmp/tmpBTbBKB/PD_evolve.o -L/home/rajeev/bin/sage/local/lib -lpython2.6 > -lgfortran -o ./PD_evolve.so > /usr/lib/gcc/i486-linux-gnu/4.4.5/libgfortranbegin.a(fmain.o): In function > `main': > (.text+0x27): undefined reference to `MAIN__' > collect2: ld returned 1 exit status > /usr/lib/gcc/i486-linux-gnu/4.4.5/libgfortranbegin.a(fmain.o): In function > `main': > (.text+0x27): undefined reference to `MAIN__' > collect2: ld returned 1 exit status > error: Command "/usr/bin/gfortran -Wall > /tmp/tmpBTbBKB/tmp/tmpBTbBKB/src.linux-i686-2.6/PD_evolvemodule.o > /tmp/tmpBTbBKB/tmp/tmpBTbBKB/src.linux-i686-2.6/fortranobject.o > /tmp/tmpBTbBKB/PD_evolve.o -L/home/rajeev/bin/sage/local/lib -lpython2.6 > -lgfortran -o ./PD_evolve.so" failed with exit status 1 > > I have compiled sage4.6.2 from source on Debian squeeze. I hope it makes > sense to ask this question here as the trouble is within sage. > > Rajeev > Hi, Going through the source code of numpy.f2py.compile and fortran in sage, I managed to get things working. The following code works just fine - path = os.environ['SAGE_LOCAL']+'/bin/sage-g77_shared' extra_args = '--f77exec=%s --f90exec=%s' %(path, path) args = ' -c -m %s %s %s'%('PD_evolve', 'PD_evolve.f90', extra_args) cmd = '%s -c "import numpy.f2py as f2py2e;f2py2e.main()" %s' %(sys.executable,args) os.system(cmd) The other thing that worked was InlineFortran from sage.misc.inline_fortran however it would compile the source every time I run the program, whereas the above set of instructions create a .so file which can be imported directly in future runs. This is just for future reference. Rajeev -- To post to this group, send email to sage-support@googlegroups.com To unsubscribe from this group, send email to sage-support+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/sage-support URL: http://www.sagemath.org