
Hi all, I have recently started using f2py to access some legacy fortran code and it's mostly worked better than I expected. It handles common blocks, block data, etc. with no problems. I did need to define the type of all the arguments in subroutine and function calls, but not in the body of the code (though of course that would be good programming practice). The one thing that I haven't been able to get to work is linking to code in an object library. My normal approach to compiling my code that uses this particular code collection (RS) goes like: f77 -c (...other options) main_prog.f f77 -o main_prog main_prog.o -L/lib_dir -lRS where /lib_dir is the directory where the library resides and the library name is libRS.a The library was created by via: ar cru libRS.a file1.o file2.o (...list of object files, compiled fortran routines) ranlib libRS.a f2py does accept the -L and -l arguments but doesn't seem to be able to find the code in the libraries. Any suggestions? Jon -- ______________________________________________________________ Jonathan D. Slavin Harvard-Smithsonian CfA jslavin@cfa.harvard.edu 60 Garden Street, MS 83 phone: (617) 496-7981 Cambridge, MA 02138-1516 cell: (781) 363-0035 USA ______________________________________________________________

Hi Jon, I have personally never used f2py to link to library code, but according to the documentation: http://cens.ioc.ee/projects/f2py2e/usersguide/index.html#command-f2py if you are building a module (that is, invoking f2py -c), then you can either include the path to the .a file directly at the end of the list, or you can use the -L and -l flags. f2py -c <options> <fortran files> \ [[ only: <fortran functions> : ] \ [ skip: <fortran functions> : ]]... \ [ <fortran/c source files> ] [ <.o, .a, .so files> ] One trap I've run into in the past is that if the object code library was not compiled with the correct compiler flags (-fPIC, or target architecture), the linker will actually skip over the incompatible library. Usually you will see some sort of warning or complaint. Do you mind running with the --verbose option and posting the complete log somewhere, including the commands you are using to build the library and your invocation of f2py? Cheers, Aron On Thu, Apr 25, 2013 at 6:34 PM, Jonathan Slavin <jslavin@cfa.harvard.edu>wrote:
Hi all,
I have recently started using f2py to access some legacy fortran code and it's mostly worked better than I expected. It handles common blocks, block data, etc. with no problems. I did need to define the type of all the arguments in subroutine and function calls, but not in the body of the code (though of course that would be good programming practice). The one thing that I haven't been able to get to work is linking to code in an object library. My normal approach to compiling my code that uses this particular code collection (RS) goes like: f77 -c (...other options) main_prog.f f77 -o main_prog main_prog.o -L/lib_dir -lRS where /lib_dir is the directory where the library resides and the library name is libRS.a The library was created by via: ar cru libRS.a file1.o file2.o (...list of object files, compiled fortran routines) ranlib libRS.a f2py does accept the -L and -l arguments but doesn't seem to be able to find the code in the libraries. Any suggestions?
Jon -- ______________________________________________________________ Jonathan D. Slavin Harvard-Smithsonian CfA jslavin@cfa.harvard.edu 60 Garden Street, MS 83 phone: (617) 496-7981 Cambridge, MA 02138-1516 cell: (781) 363-0035 USA ______________________________________________________________
_______________________________________________ NumPy-Discussion mailing list NumPy-Discussion@scipy.org http://mail.scipy.org/mailman/listinfo/numpy-discussion
participants (2)
-
Aron Ahmadia
-
Jonathan Slavin