f2py FORTRAN 2 Python Wrapper--> -lg2c Error

Wenn du dir nicht sicher bist, in welchem der anderen Foren du die Frage stellen sollst, dann bist du hier im Forum für allgemeine Fragen sicher richtig.
Antworten
acidk
User
Beiträge: 75
Registriert: Samstag 6. Januar 2007, 18:54
Wohnort: Braunschweig

Hallo Leute!

Ich hab mich aus Neugier mal an ein bisschen Fortran versucht, bin über f2py gestolpert, und fand die Idee das ganze nach Python zu wrappen sehr reizvoll.

alle Beispiele hab ich hierher:
http://cens.ioc.ee/projects/f2py2e/

erste Versuche:

1.

Create a Fortran file hello.f that contains:

Code: Alles auswählen

   C File hello.f
            subroutine foo (a)
            integer a
            print*, "Hello from Fortran!"
            print*, "a=",a
            end
2. Run

Code: Alles auswählen

flo@AKB-34:~/Desktop/FORTRAN$ f2py -c -m hello hello.f
numpy_info:
  FOUND:
    define_macros = [('NUMERIC_VERSION', '"\\"24.2\\""'), ('NUMERIC', None)]
    include_dirs = ['/usr/include/python2.5']

running build
running config_fc
running build_src
applying backend (numeric) info to extensions
building extension "hello" sources
f2py:> /tmp/tmp4Sc3Nd/src/hellomodule.c
creating /tmp/tmp4Sc3Nd
creating /tmp/tmp4Sc3Nd/src
Reading fortran codes...
	Reading file 'hello.f'
Post-processing...
	Block: hello
			Block: foo
Post-processing (stage 2)...
Building modules...
	Building module "hello"...
		Constructing wrapper function "foo"...
		  foo(a)
	Wrote C/API module "hello" to file "/tmp/tmp4Sc3Nd/src/hellomodule.c"
  adding '/tmp/tmp4Sc3Nd/src/fortranobject.c' to sources.
  adding '/tmp/tmp4Sc3Nd/src' to include_dirs.
copying /usr/lib/python2.5/site-packages/f2py2e/src/fortranobject.c -> /tmp/tmp4Sc3Nd/src
copying /usr/lib/python2.5/site-packages/f2py2e/src/fortranobject.h -> /tmp/tmp4Sc3Nd/src
running build_ext
customize UnixCCompiler
customize UnixCCompiler using build_ext
Could not locate executable g77
customize GnuFCompiler
Could not locate executable ifort
Could not locate executable ifc
Could not locate executable efort
Could not locate executable efc
Could not locate executable ifort
customize IntelFCompiler
customize LaheyFCompiler
customize PGroupFCompiler
customize AbsoftFCompiler
customize NAGFCompiler
customize VastFCompiler
customize GnuFCompiler
customize CompaqFCompiler
customize IntelItaniumFCompiler
customize G95FCompiler
customize GnuFCompiler
customize GnuFCompiler
customize GnuFCompiler using build_ext
building 'hello' extension
compiling C sources
gcc options: '-pthread -fno-strict-aliasing -DNDEBUG -g -fwrapv -O2 -Wall -Wstrict-prototypes -fPIC'
creating /tmp/tmp4Sc3Nd/tmp
creating /tmp/tmp4Sc3Nd/tmp/tmp4Sc3Nd
creating /tmp/tmp4Sc3Nd/tmp/tmp4Sc3Nd/src
compile options: '-DNUMERIC_VERSION="\"24.2\"" -DNUMERIC -I/usr/include/python2.5 -I/tmp/tmp4Sc3Nd/src -I/usr/include/python2.5 -c'
gcc: /tmp/tmp4Sc3Nd/src/fortranobject.c
gcc: /tmp/tmp4Sc3Nd/src/hellomodule.c
compiling Fortran sources
f77(f77) options: '-Wall -fno-second-underscore -fPIC -O2 -funroll-loops -march=i686 -malign-double -fomit-frame-pointer'
compile options: '-I/usr/include/python2.5 -I/tmp/tmp4Sc3Nd/src -I/usr/include/python2.5 -c'
f77:f77: hello.f
   foo:
cc1: Warnung: Kommandozeilenoption "-fno-second-underscore" ist g�ltig f�r Fortran, aber nicht f�r C
/usr/bin/f77 -shared /tmp/tmp4Sc3Nd/tmp/tmp4Sc3Nd/src/hellomodule.o /tmp/tmp4Sc3Nd/tmp/tmp4Sc3Nd/src/fortranobject.o /tmp/tmp4Sc3Nd/hello.o -lg2c -o ./hello.so
/usr/bin/ld: cannot find -lg2c
collect2: ld gab 1 als Ende-Status zur�ck
Removing build directory /tmp/tmp4Sc3Nd
*hmpf*
ich hab das -lg2c gegoogelt und hab daraufhin libg2c0 installiert. Hat leider nichts gebracht.
Hat Jemand von Euch eine Idee??

Vielen Dank & Gru�,

flo

ach ja -- os ist ubuntu 8.10 intrepid ;-)
Benutzeravatar
mkesper
User
Beiträge: 919
Registriert: Montag 20. November 2006, 15:48
Wohnort: formerly known as mkallas
Kontaktdaten:

Probier mal libg2c0-dev. Zum Entwickeln / Übersetzen braucht man immer die -dev-Pakete von Libraries.
acidk
User
Beiträge: 75
Registriert: Samstag 6. Januar 2007, 18:54
Wohnort: Braunschweig

Danke! mit dem Kompilieren hats schonmal geklappt -- auf die Idee mit den dev Paketen hätte ich eigentlich auch selbst kommen können :oops: *schäm*

kompilieren liefert:

flo@AKB-34:~/Desktop/FORTRAN$ f2py -c -m hello hello.f

Code: Alles auswählen

numpy_info:
  FOUND:
    define_macros = [('NUMERIC_VERSION', '"\\"24.2\\""'), ('NUMERIC', None)]
    include_dirs = ['/usr/include/python2.5']

running build
running config_fc
running build_src
applying backend (numeric) info to extensions
building extension "hello" sources
f2py:> /tmp/tmpwg-Ae8/src/hellomodule.c
creating /tmp/tmpwg-Ae8
creating /tmp/tmpwg-Ae8/src
Reading fortran codes...
	Reading file 'hello.f'
Post-processing...
	Block: hello
			Block: foo
Post-processing (stage 2)...
Building modules...
	Building module "hello"...
		Constructing wrapper function "foo"...
		  foo(a)
	Wrote C/API module "hello" to file "/tmp/tmpwg-Ae8/src/hellomodule.c"
  adding '/tmp/tmpwg-Ae8/src/fortranobject.c' to sources.
  adding '/tmp/tmpwg-Ae8/src' to include_dirs.
copying /usr/lib/python2.5/site-packages/f2py2e/src/fortranobject.c -> /tmp/tmpwg-Ae8/src
copying /usr/lib/python2.5/site-packages/f2py2e/src/fortranobject.h -> /tmp/tmpwg-Ae8/src
running build_ext
customize UnixCCompiler
customize UnixCCompiler using build_ext
Could not locate executable g77
customize GnuFCompiler
Could not locate executable ifort
Could not locate executable ifc
Could not locate executable efort
Could not locate executable efc
Could not locate executable ifort
customize IntelFCompiler
customize LaheyFCompiler
customize PGroupFCompiler
customize AbsoftFCompiler
customize NAGFCompiler
customize VastFCompiler
customize GnuFCompiler
customize CompaqFCompiler
customize IntelItaniumFCompiler
customize G95FCompiler
customize GnuFCompiler
customize GnuFCompiler
customize GnuFCompiler using build_ext
building 'hello' extension
compiling C sources
gcc options: '-pthread -fno-strict-aliasing -DNDEBUG -g -fwrapv -O2 -Wall -Wstrict-prototypes -fPIC'
creating /tmp/tmpwg-Ae8/tmp
creating /tmp/tmpwg-Ae8/tmp/tmpwg-Ae8
creating /tmp/tmpwg-Ae8/tmp/tmpwg-Ae8/src
compile options: '-DNUMERIC_VERSION="\"24.2\"" -DNUMERIC -I/usr/include/python2.5 -I/tmp/tmpwg-Ae8/src -I/usr/include/python2.5 -c'
gcc: /tmp/tmpwg-Ae8/src/fortranobject.c
gcc: /tmp/tmpwg-Ae8/src/hellomodule.c
compiling Fortran sources
f77(f77) options: '-Wall -fno-second-underscore -fPIC -O2 -funroll-loops -march=i686 -malign-double -fomit-frame-pointer'
compile options: '-I/usr/include/python2.5 -I/tmp/tmpwg-Ae8/src -I/usr/include/python2.5 -c'
f77:f77: hello.f
   foo:
cc1: Warnung: Kommandozeilenoption "-fno-second-underscore" ist gültig für Fortran, aber nicht für C
/usr/bin/f77 -shared /tmp/tmpwg-Ae8/tmp/tmpwg-Ae8/src/hellomodule.o /tmp/tmpwg-Ae8/tmp/tmpwg-Ae8/src/fortranobject.o /tmp/tmpwg-Ae8/hello.o -lg2c -o ./hello.so
Removing build directory /tmp/tmpwg-Ae8
Tja -- Aufruf in Python:


flo@AKB-34:~/Desktop/FORTRAN$ python

Code: Alles auswählen

Python 2.5.2 (r252:60911, Oct  5 2008, 19:24:49) 
[GCC 4.3.2] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import hello
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
[b]ImportError: /usr/lib/libf2c.so.2: undefined symbol: MAIN__[/b]
>>>

... kapier ich nicht !!! Liegts am /libf2c.so.2 - oder hab ich irgendeinen Pfad nicht richtiggesetzt???

Danke!

flo
mineralwasser
User
Beiträge: 5
Registriert: Mittwoch 20. Januar 2010, 09:40

Hallo!
Ich habe versucht, das gleiche Beispiel zu rechnen, allerdings kommt bei mir folgender Fehler:

Code: Alles auswählen

numpy_info:
  FOUND:
    define_macros = [('NUMERIC_VERSION', '"\\"24.2\\""'), ('NUMERIC', None)]
    include_dirs = ['/usr/include/python2.6']

running build
running config_fc
running build_src
applying backend (numeric) info to extensions
building extension "hello" sources
f2py:> /tmp/tmpsdMXLG/src/hellomodule.c
creating /tmp/tmpsdMXLG
creating /tmp/tmpsdMXLG/src
Reading fortran codes...
	Reading file 'hello.f'
Post-processing...
	Block: hello
			Block: foo
Post-processing (stage 2)...
Building modules...
	Building module "hello"...
		Constructing wrapper function "foo"...
		  foo(a)
	Wrote C/API module "hello" to file "/tmp/tmpsdMXLG/src/hellomodule.c"
  adding '/tmp/tmpsdMXLG/src/fortranobject.c' to sources.
  adding '/tmp/tmpsdMXLG/src' to include_dirs.
copying /usr/local/lib/python2.6/dist-packages/f2py2e/src/fortranobject.c -> /tmp/tmpsdMXLG/src
copying /usr/local/lib/python2.6/dist-packages/f2py2e/src/fortranobject.h -> /tmp/tmpsdMXLG/src
running build_ext
customize UnixCCompiler
customize UnixCCompiler using build_ext
Could not locate executable g77
Could not locate executable f77
customize GnuFCompiler
Could not locate executable ifort
Could not locate executable ifc
Could not locate executable efort
Could not locate executable efc
Could not locate executable ifort
customize IntelFCompiler
customize LaheyFCompiler
customize PGroupFCompiler
customize AbsoftFCompiler
customize NAGFCompiler
customize VastFCompiler
customize GnuFCompiler
customize CompaqFCompiler
customize IntelItaniumFCompiler
customize G95FCompiler
customize GnuFCompiler
customize GnuFCompiler
customize GnuFCompiler using build_ext
building 'hello' extension
compiling C sources
gcc options: '-pthread -fno-strict-aliasing -DNDEBUG -g -fwrapv -O2 -Wall -Wstrict-prototypes -fPIC'
creating /tmp/tmpsdMXLG/tmp
creating /tmp/tmpsdMXLG/tmp/tmpsdMXLG
creating /tmp/tmpsdMXLG/tmp/tmpsdMXLG/src
compile options: '-DNUMERIC_VERSION="\"24.2\"" -DNUMERIC -I/usr/include/python2.6 -I/tmp/tmpsdMXLG/src -I/usr/include/python2.6 -c'
gcc: /tmp/tmpsdMXLG/src/fortranobject.c
In file included from /tmp/tmpsdMXLG/src/fortranobject.c:2:
/tmp/tmpsdMXLG/src/fortranobject.h:7:20: error: Python.h: No such file or directory
In file included from /tmp/tmpsdMXLG/src/fortranobject.h:33,
                 from /tmp/tmpsdMXLG/src/fortranobject.c:2:
/usr/include/python2.6/Numeric/arrayobject.h:23: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘*’ token
/usr/include/python2.6/Numeric/arrayobject.h:24: error: expected ‘)’ before ‘*’ token
/usr/include/python2.6/Numeric/arrayobject.h:29: error: expected specifier-qualifier-list before ‘PyArray_GetItemFunc’

...


Habt ihr ne Idee, woran das liegen könnte?
mineralwasser
User
Beiträge: 5
Registriert: Mittwoch 20. Januar 2010, 09:40

habs selbst gefunden....

man braucht Python2.6-dev, da ist die Python.h dabei.
CM
User
Beiträge: 2464
Registriert: Sonntag 29. August 2004, 19:47
Kontaktdaten:

Hallo und willkommen im Forum,
mineralwasser hat geschrieben:

Code: Alles auswählen

/tmp/tmpsdMXLG/src/fortranobject.h:7:20: error: Python.h: No such file or directory
Habt ihr ne Idee, woran das liegen könnte?
Nun, Dir fehlt wahrscheinlich "Python.h". D. h. Du solltest erst einmal das Python-dev-Paket Deines Systems nachinstallieren. Ich vermute Du arbeitest mit einer Linux-Machine. Da sollte das eigentlich irgendwo in der Paketverwaltung schlummern.

HTH
Christian

edit: Zu spät ...
mineralwasser
User
Beiträge: 5
Registriert: Mittwoch 20. Januar 2010, 09:40

Trotzdem vielen Dank! ;-)

allerdings habe ich schon den nächsten Fehler:

Code: Alles auswählen

malte@malte-laptop:~/f2py$ f2py -c -m hello hello.f 
numpy_info:
  FOUND:
    define_macros = [('NUMERIC_VERSION', '"\\"24.2\\""'), ('NUMERIC', None)]
    include_dirs = ['/usr/include/python2.6']

running build
running config_fc
running build_src
applying backend (numeric) info to extensions
building extension "hello" sources
f2py:> /tmp/tmpIP89mF/src/hellomodule.c
creating /tmp/tmpIP89mF
creating /tmp/tmpIP89mF/src
Reading fortran codes...
	Reading file 'hello.f'
Post-processing...
	Block: hello
			Block: foo
Post-processing (stage 2)...
Building modules...
	Building module "hello"...
		Constructing wrapper function "foo"...
		  foo(a)
	Wrote C/API module "hello" to file "/tmp/tmpIP89mF/src/hellomodule.c"
  adding '/tmp/tmpIP89mF/src/fortranobject.c' to sources.
  adding '/tmp/tmpIP89mF/src' to include_dirs.
copying /usr/local/lib/python2.6/dist-packages/f2py2e/src/fortranobject.c -> /tmp/tmpIP89mF/src
copying /usr/local/lib/python2.6/dist-packages/f2py2e/src/fortranobject.h -> /tmp/tmpIP89mF/src
running build_ext
customize UnixCCompiler
customize UnixCCompiler using build_ext
Could not locate executable g77
Could not locate executable f77
customize GnuFCompiler
Could not locate executable ifort
Could not locate executable ifc
Could not locate executable efort
Could not locate executable efc
Could not locate executable ifort
customize IntelFCompiler
customize LaheyFCompiler
customize PGroupFCompiler
customize AbsoftFCompiler
customize NAGFCompiler
customize VastFCompiler
customize GnuFCompiler
customize CompaqFCompiler
customize IntelItaniumFCompiler
customize G95FCompiler
customize GnuFCompiler
customize GnuFCompiler
customize GnuFCompiler using build_ext
building 'hello' extension
compiling C sources
gcc options: '-pthread -fno-strict-aliasing -DNDEBUG -g -fwrapv -O2 -Wall -Wstrict-prototypes -fPIC'
creating /tmp/tmpIP89mF/tmp
creating /tmp/tmpIP89mF/tmp/tmpIP89mF
creating /tmp/tmpIP89mF/tmp/tmpIP89mF/src
compile options: '-DNUMERIC_VERSION="\"24.2\"" -DNUMERIC -I/usr/include/python2.6 -I/tmp/tmpIP89mF/src -I/usr/include/python2.6 -c'
gcc: /tmp/tmpIP89mF/src/fortranobject.c
/tmp/tmpIP89mF/src/fortranobject.c: In function ‘fortran_doc’:
/tmp/tmpIP89mF/src/fortranobject.c:123: warning: format ‘%d’ expects type ‘int’, but argument 3 has type ‘size_t’
gcc: /tmp/tmpIP89mF/src/hellomodule.c
compiling Fortran sources
f77(f77) options: '-Wall -fno-second-underscore -fPIC -O2 -funroll-loops -march=i686 -malign-double -fomit-frame-pointer'
compile options: '-I/usr/include/python2.6 -I/tmp/tmpIP89mF/src -I/usr/include/python2.6 -c'
f77:f77: hello.f
sh: f77: not found
sh: f77: not found
error: Command "f77 -Wall -fno-second-underscore -fPIC -O2 -funroll-loops -march=i686 -malign-double -fomit-frame-pointer -I/usr/include/python2.6 -I/tmp/tmpIP89mF/src -I/usr/include/python2.6 -c -c hello.f -o /tmp/tmpIP89mF/hello.o" failed with exit status 127
Ich hab keinen Plan was ich machen soll...
Scheint, als liegts daran, dass ich keinen f77-compiler habe.
Braucht man den unbedingt bzw. gibts den als free-download?
CM
User
Beiträge: 2464
Registriert: Sonntag 29. August 2004, 19:47
Kontaktdaten:

Na ja, das war ja auch schon in der vorherigen Meldung enthalten.
Vielleicht hilft dies?
mineralwasser
User
Beiträge: 5
Registriert: Mittwoch 20. Januar 2010, 09:40

Das Problem ist, dass der meinen gfortran-compiler nicht erkennt.
Genau genommen erkennt er gar keinen.

Code: Alles auswählen

List of available Fortran compilers:
List of unavailable Fortran compilers:
  --fcompiler=absoft   Absoft Corp Fortran Compiler
  --fcompiler=compaq   Compaq Fortran Compiler
  --fcompiler=compaqv  DIGITAL|Compaq Visual Fortran Compiler
  --fcompiler=g95      GNU Fortran 95 Compiler
  --fcompiler=gnu      GNU Fortran Compiler
  --fcompiler=hpux     HP Fortran 90 Compiler
  --fcompiler=ibm      IBM XL Fortran Compiler
  --fcompiler=intel    Intel Fortran Compiler for 32-bit apps
  --fcompiler=intele   Intel Fortran Compiler for Itanium apps
  --fcompiler=intelev  Intel Visual Fortran Compiler for Itanium apps
  --fcompiler=intelv   Intel Visual Fortran Compiler for 32-bit apps
  --fcompiler=lahey    Lahey/Fujitsu Fortran 95 Compiler
  --fcompiler=mips     MIPSpro Fortran Compiler
  --fcompiler=nag      NAGWare Fortran 95 Compiler
  --fcompiler=pg       Portland Group Fortran Compiler
  --fcompiler=sun      Sun|Forte Fortran 95 Compiler
  --fcompiler=vast     Pacific-Sierra Research Fortran 90 Compiler
List of unimplemented Fortran compilers:
  --fcompiler=f  Fortran Company/NAG F Compiler
For compiler details, run 'config_fc --verbose' setup command.
Ich habe einen Seite gefunden, wo jemand scheinbar genau das gleich Problem hatte.
http://article.gmane.org/gmane.comp.pyt ... y.user/977

Er sagt, man solle Numpy über das SVN auschecken und dann installieren, weil bei seiner Version wohl noch irgendein Bug dabei war. (Dieser müsste aber mittlerweile eigentlich beseitigt sein.)
Vielleicht liegts auch daran, dass ich mein Numpy über diese Synaptic-Paketverwaltung installiert habe und der dafür standardmäßig verwendete Compiler NICHT der gfortran ist, ergo könnte es sein, dass man f2py auch nicht mehr mit dem gfortran compilieren kann.
Man müsste also numpy erst mit dem gfortran installieren.
Ich hab mir jetzt die neueste numpy Version aus dem SVN runtergeladen und installiert (mit dem gfortran) allerdings funktionierts immer noch nicht.
Ich glaube, aber auch, das meine svn-numpy installation nicht so ganz geklappt hat....muss man einfach nur

sudo python setup.py install

eingeben und sofort sind die Module zum importieren verfügbar? Muss man vielleicht noch irgendwelche Pfade angeben?

Schonmal Vielen Dank im Vorraus :)
CM
User
Beiträge: 2464
Registriert: Sonntag 29. August 2004, 19:47
Kontaktdaten:

Synaptic? Das ist ein Hinweis. Du arbeitest also wahrscheinlich mit einem Ubuntu-Derivat, oder?

Also bei mir klappt das Beispiel problemlos und ohne zusätzliche Compilerflags. Ich habe ebenfalls Ubuntu und nur folgende Pakete:
- gfortran / gfortran4.3
- python-numpy
Und natürlich die dev-Pakete, sofern nötig. Funktioniet einwandfrei, deshalb habe ich Zweifel, ob dieser Mailinglistenthread sehr hilfreich ist.

Hast Du den gfortran installiert? Was sagt "which gfortran"?
mineralwasser
User
Beiträge: 5
Registriert: Mittwoch 20. Januar 2010, 09:40

malte@malte-laptop:~$ which gfortran
/usr/bin/gfortran

Ich benutzt Ubuntu 9.10, da ist auch bisher nicht viel gemacht worden, ich brauchs eigentlich nur für das f2py ;-)

Kannst du mir nochmal genau sagen, wie ich numpy mit gfortran installiere?
CM
User
Beiträge: 2464
Registriert: Sonntag 29. August 2004, 19:47
Kontaktdaten:

Das sind zwei unabhändgige Pakete.

Offengestanden gehen mir die Ideen aus. Wenn hier niemand weiter weiß, magst Du vielleicht auf der numpy-Mailingliste fragen? Aber nicht wieder vergessen welches OS Du nutzt und welche numpy-Version.

Gruß,
Christian
Antworten