Opened 11 years ago

Closed 11 years ago

Last modified 11 years ago

#41122 closed defect (fixed)

py-obspy obspy.taup.taup ImportError: libtaup not linked to libgfortran.a

Reported by: anowacki (Andy Nowacki) Owned by: petrrr
Priority: Normal Milestone:
Component: ports Version: 2.2.1
Keywords: Cc:
Port: py-obspy

Description

When trying to use py-obspy on OS X 10.8.5, one cannot load the obspy.taup module:

$ sudo port install py27-obspy @gcc46
--- snip ---
$ /opt/local/bin/python2.7
Python 2.7.5 (default, Aug  1 2013, 01:01:17) 
[GCC 4.2.1 Compatible Apple Clang 4.1 ((tags/Apple/clang-421.11.66))] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> from obspy.taup import taup
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/obspy/taup/taup.py", line 8, in <module>
    from obspy.taup.util import flibtaup as lib
  File "/opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/obspy/taup/util.py", line 34, in <module>
    raise ImportError(msg)
ImportError: Could not load shared library for obspy.taup.

 dlopen(/opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/obspy/taup/../lib/libtaup.so, 6): Symbol not found: __gfortran_compare_string
  Referenced from: /opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/obspy/taup/../lib/libtaup.so
  Expected in: flat namespace
 in /opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/obspy/taup/../lib/libtaup.so
>>> 

This occurs because the Patch file for the port source:trunk/dports/python/py-obspy/files/patch-setup.py.diff contains the line:

@@ -621,7 +620,6 @@
     taupargs = []
 
     lib = MyExtension(lib_name,
-                       libraries=['gfortran'],
                       extra_link_args=extra_link_args,
                       sources=[src + 'emdlv.f', src + 'libtau.f',
                                src + 'ttimes_subrout.f'])

Hence, during the final link stage, /usr/bin/clang does not link to libgfortran, hence the missing reference to __gfortran_compare_string. Removing removing this part of the diff does not help. This time, /usr/bin/clang cannot link to -lgfortran because it can't be found in the usual MacPorts location of ${prefix}/lib: it is acutally in ${prefix}/lib/gcc${ver_no_dot} (e.g., /opt/local/lib/gcc46 in may case).

I'm afraid I know very little about portfiles and how MacPorts works in general, but I tried a number of things without success:

  1. $ sudo LIBRARY_PATH=/opt/local/lib/gcc46 install py27-obspy +gcc46

The rationale is that setup.py searches LIBRARY_PATH for directories to add in the final link stage. However, I could never get this to be picked up.

  1. Editing the source:trunk/dports/python/py-obspy/Portfile to add configure.env-append ${prefix}/lib/gcc${ver_no_dot}
  1. Adding extra_env LIBRARY_PATH to $prefix/etc/macports/macports.conf.

In the end, I replaced the source:trunk/dports/python/py-obspy/files/patch-setup.py.diff with the attached file (pertinent bit below).

@@ -621,7 +620,7 @@
     taupargs = []
 
     lib = MyExtension(lib_name,
                       libraries=['gfortran'],
-                      extra_link_args=extra_link_args,
+                      extra_link_args=['-L/opt/local/lib/gcc46'],
                       sources=[src + 'emdlv.f', src + 'libtau.f',
                                src + 'ttimes_subrout.f'])

This is obviously not a satisfactory fix at all, but like I say, I don't know how to do this more generally.

I hope this helps the maintainers or someone else more conversant with MacPorts to get obspy working 'out of the box' from here on.

Attachments (4)

patch-setup.py.diff (1.4 KB) - added by anowacki (Andy Nowacki) 11 years ago.
patch.Portfile.diff (3.2 KB) - added by petrrr 11 years ago.
fix and some other changes
patch.files-patch-setup.py.diff (951 bytes) - added by petrrr 11 years ago.
fix; the setup.py needs this patch
patch.py-obspy.diff (4.4 KB) - added by petrrr 11 years ago.
updated fix, now works for py26 as well

Download all attachments as: .zip

Change History (13)

Changed 11 years ago by anowacki (Andy Nowacki)

Attachment: patch-setup.py.diff added

comment:1 in reply to:  description ; Changed 11 years ago by ryandesign (Ryan Carsten Schmidt)

Cc: peter.danecek@… removed
Owner: changed from macports-tickets@… to Peter.Danecek@…

Replying to andy.nowacki@…:

$ sudo port install py27-obspy @gcc46

If you're trying to activate the gcc46 variant, the correct syntax is sudo port install py27-obspy +gcc46

  1. $ sudo LIBRARY_PATH=/opt/local/lib/gcc46 install py27-obspy +gcc46

The rationale is that setup.py searches LIBRARY_PATH for directories to add in the final link stage. However, I could never get this to be picked up.

MacPorts intentionally ignores your shell environment so that it will not adversely affect a build.

  1. Adding extra_env LIBRARY_PATH to $prefix/etc/macports/macports.conf.

You should not set LIBRARY_PATH nor should you list it in extra_env.

comment:2 in reply to:  1 Changed 11 years ago by anowacki (Andy Nowacki)

Replying to ryandesign@…:

If you're trying to activate the gcc46 variant, the correct syntax is sudo port install py27-obspy +gcc46

That would be a typo--thanks for spotting it in case it threw anyone else off.

MacPorts intentionally ignores your shell environment so that it will not adversely affect a build. You should not set LIBRARY_PATH nor should you list it in extra_env.

As I mentioned, this was just a dirty hack attempt--if I knew how to add linker options to setup.py in a MacPorts build in a portable and general way, you'd have a patch for the portfile and patch file by now! I'll leave it to Peter to work his magic then, I guess.

comment:3 Changed 11 years ago by petrrr

Thanks for spotting this!

The setup.py of ObsPy is definitively problematic. Actually, it was already substituted but was not backported to 0.8.4. I assume the point here is that when I created and tested the port we still were using the same version of gcc and gfortran. That way linking was done by the "correct" gcc version and know about the correct location of the lib. Now, we use gcc only for fortran and link with a different C compiler.

I will try to fix this soon. However, I am travelling and cannot do this immediately.

comment:4 Changed 11 years ago by petrrr

I was looking at different options to solve this, but at the end I am inclined to just use the corresponding Macports gcc compiler also for compiling the C extensions and for linking. This would revert this port to the behavior it had before transitioning to the GFortran Recipe. In the end it should have little effect on the C extensions and using gcc-mp-* solves the problem with finding libgfortran without having to deal with build.env etc. too much.

Are there any contraindications for this?

Changed 11 years ago by petrrr

Attachment: patch.Portfile.diff added

fix and some other changes

Changed 11 years ago by petrrr

fix; the setup.py needs this patch

comment:5 Changed 11 years ago by petrrr

Here the proposed fix for this ticket. Along with the fix I introduced some further minor changes to the Portfile:

  • long_description reformatted to fit 80 column width;
  • update master_sites to avoid redirect;
  • add livecheck to this port;

The fix is implemented by:

  • adding configure.cc ${prefix}/bin/gcc-mp-${ver} to avoid fuss with libgfortran while linking;
  • modifying the patch to setup.py;

Note: The setup.py script is going to become obsolete with release of 0.9.x, so this fix can be considered temporary.

To the commiter: Please ignore most of the attached files and apply only patch.py-obspy.diff. Sor​ry for the confusion, but I guess there in no way to cancel attached files again.

comment:6 Changed 11 years ago by petrrr

STOP: One moment please!

I am just testing with python 2.6 and the fix above seems not to work for Python 2.6. Here always clang is used for linking. So just setting the C compiler does not help here.

Need to approach this in a different way.

Changed 11 years ago by petrrr

Attachment: patch.py-obspy.diff added

updated fix, now works for py26 as well

comment:7 Changed 11 years ago by petrrr

Here a fix which works for both py26 and py27. The fix includes some changes to the Portfile, as specified above.

To the committer: Apply only patch.py-obspy.diff! The other files are irrelevant.

comment:8 Changed 11 years ago by mojca (Mojca Miklavec)

Resolution: fixed
Status: newclosed

comment:9 Changed 11 years ago by anowacki (Andy Nowacki)

Thanks Peter--works fine for me.

Note: See TracTickets for help on using tickets.