473,387 Members | 1,757 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

Using Fortran libraries from Python?

I have experimented with f2c and swig-generated wrappers to create python
modules from Fortran files.

I think I'm missing something when I'm building the Python module, because
when I import the built module the Python interpreter returns the
following:
import LDSsobol
Traceback (most recent call last):
File "<stdin>", line 1, in ?
File "LDSsobol.py", line 4, in ?
import _LDSsobol
ImportError: /usr/lib/libf2c.so.0: undefined symbol: MAIN__

This is how I built LDSsobol:
gcc -c LDSsobol.c
gcc -c LDSsobol_wrap.c -I/usr/include/python
gcc -shared LDSsobol.o LDSsobol_wrap.o -l f2c -o _LDSsobol.so


Any help is appreciated!

Carl
Jul 18 '05 #1
5 3042

Carl> I have experimented with f2c and swig-generated wrappers to create
Carl> python modules from Fortran files.

...

Carl> Any help is appreciated!

I'd take a look at f2py, part of the scipy package (and also available on
its own):

http://www.scipy.org/
http://www.python.org/pypi?%3Aaction..._pypi_hidden=0

Skip

Jul 18 '05 #2
Carl <ph***********@chello.se> writes:
I have experimented with f2c and swig-generated wrappers to create python
modules from Fortran files.

I think I'm missing something when I'm building the Python module, because
when I import the built module the Python interpreter returns the
following:
import LDSsobol

Traceback (most recent call last):
File "<stdin>", line 1, in ?
File "LDSsobol.py", line 4, in ?
import _LDSsobol
ImportError: /usr/lib/libf2c.so.0: undefined symbol: MAIN__

This is how I built LDSsobol:
gcc -c LDSsobol.c
gcc -c LDSsobol_wrap.c -I/usr/include/python
gcc -shared LDSsobol.o LDSsobol_wrap.o -l f2c -o _LDSsobol.so


Hello Carl,

Googleing for "libf2c.so.0: undefined symbol: MAIN__" I found only 8
hits, some links broken, but also

<http://www.physics.orst.edu/~bertrand/slatec/jnislatec/JNI_Slatec.html>

where I found:

Currently users of f2c will probably encounter the following message:
"libf2c.so.0: undefined symbol: MAIN__ ". Again, the culprit is that
all references must be resolved, and libf2c.so unfortunately contains
a reference to some dummy function. Fortunately the fix is simple,
include the following snippet in your C native source (in our example
mynativecalls.c):

int MAIN__( )
{ return(0);
}

Another solution (not tested) could be to use "-lg2c" instead of
"-lf2c". As I understand it, the g77 runtime library is derived from
the f2c runtime library. An even better (in my opinion) solution would
be to use "f2py" from <http://cens.ioc.ee/projects/f2py2e/>, a tool to
wrap python (and C) code for python.

Regards
Berthold
--
bh***@web.de / http://starship.python.net/crew/bhoel/
Jul 18 '05 #3
Carl <ph***********@chello.se> writes:
I have experimented with f2c and swig-generated wrappers to create python
modules from Fortran files.

I think I'm missing something when I'm building the Python module, because
when I import the built module the Python interpreter returns the
following:
import LDSsobol

Traceback (most recent call last):
File "<stdin>", line 1, in ?
File "LDSsobol.py", line 4, in ?
import _LDSsobol
ImportError: /usr/lib/libf2c.so.0: undefined symbol: MAIN__

This is how I built LDSsobol:
gcc -c LDSsobol.c
gcc -c LDSsobol_wrap.c -I/usr/include/python
gcc -shared LDSsobol.o LDSsobol_wrap.o -l f2c -o _LDSsobol.so


Any help is appreciated!

Carl


Did you start with pyfort?
http://sourceforge.net/projects/pyfortran

I haven't used it personally, but it seems to be addressing your
concerns, without ad hoc SWIGing.

--
ha************@boeing.com
6-6M21 BCA CompArch Design Engineering
Phone: (425) 342-0007
Jul 18 '05 #4
Carl wrote:
I have experimented with f2c and swig-generated wrappers to create python
modules from Fortran files.


Don't bother, just use f2py. It works beautifully (we use it everyday in
production codes).

Best,

f
Jul 18 '05 #5
> Another solution (not tested) could be to use "-lg2c" instead of
"-lf2c". As I understand it, the g77 runtime library is derived from
the f2c runtime library.
This seems to work! How did you know?
An even better (in my opinion) solution would
be to use "f2py" from <http://cens.ioc.ee/projects/f2py2e/>, a tool to
wrap python (and C) code for python.


I will try both "f2py" and all other possible solution suggestions to my
problem.

I'm positively overwhelmed by your response. You've saved me a great deal of
trouble and (I don't know how many) hours of tedious trial and error work.

Thank you!

Carl

Jul 18 '05 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Markus Faust | last post by:
Hi, I'm trying to link Fortran files generated with “Compaq Visual Fortran Optimizing Compiler Version 6.6 (Update B)” under “Enthought Edition build 1028, Python 2.3 (#46, Aug 11 2003,...
44
by: Carl | last post by:
"Nine Language Performance Round-up: Benchmarking Math & File I/O" http://www.osnews.com/story.php?news_id=5602 I think this is an unfair comparison! I wouldn't dream of developing a numerical...
7
by: byte biscuit | last post by:
Hi there everybody! The problem is the following: we have a DLL (H2O.dll) - compiled in Visual Fortran - depending in turn on another DLL. H2O.dll contains only one (1) function, with a known...
2
by: Ray J. | last post by:
I have a C++ program written and compiled on Solaris 8 with gcc. With gcc lets me compile fortran code along with the C++ program to be able to call the fortran code as a subroutine. The...
11
by: Cottonwood | last post by:
I want to call a GNU-Fortran-library from a GNU-C++ source. Is that possible at all? If yes, what is to be done to link the program? I get an error message that says that the module MAIN_ cannot...
52
by: Nomad.C | last post by:
Hi I've been thinking of learning Fortran as number crunching kinda language for my Physics degree......but then looking around the internet, people are saying that the libraries/ Algorithms once...
1
by: hanhaner | last post by:
hey, there I am new to Python and C++. Now I am trying to call some fortran subroutines in python code. I was told the good way is to write a c++ interface. I am not quite sure how to do it. ...
4
by: attackwarningred | last post by:
Dear All, Hello! I've just started to use Python and its a lovely language! I've previously programmed in Fortran 95 and have just began to use numpy. I'm having a few problems with arrays in...
53
by: Vicent Giner | last post by:
Hello. I am new to Python. It seems a very interesting language to me. Its simplicity is very attractive. However, it is usually said that Python is not a compiled but interpreted programming...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.