libf2c.so.2 - main 未定义

libf2c.so.2 - main is undefined

我会尽量做到非常具体和翔实。为了 geospatial/geoscientific 社区的利益,我想创建一个包含地球科学中使用的所有包的 Docker 文件。 Docker 文件建立在 scipy-notebook docker 堆栈之上。

问题:

我正在尝试构建 HPGL(一个 Python 地统计学包)。

对于依赖项:我使用 apt-get 构建了一些包,对于那些我无法通过 apt 安装的包,我下载了 .deb 包。下面的 Docker 文件显示了构建所有 HPGL 依赖项的步骤:

FROM jupyter/scipy-notebook

###
### HPGL - High Performance Geostatistics Library
###

USER root

RUN apt-get update && \
    apt-get install -y \ 
        gcc \
        g++ \
        libboost-all-dev

RUN apt-get update && \
    apt-get install -y \ 
        liblapack-dev \
        libblas-dev \
        liblapacke-dev

RUN apt-get update && \
    apt-get install -y \ 
        scons

RUN wget http://ftp.us.debian.org/debian/pool/main/libf/libf2c2/libf2c2_20090411-2_amd64.deb && \
    dpkg -i libf2c2_20090411-2_amd64.deb

RUN wget http://ftp.us.debian.org/debian/pool/main/libf/libf2c2/libf2c2-dev_20090411-2_amd64.deb && \
    dpkg -i libf2c2-dev_20090411-2_amd64.deb

RUN wget http://mirrors.kernel.org/ubuntu/pool/universe/c/clapack/libcblas3_3.2.1+dfsg-1_amd64.deb  && \
    dpkg -i libcblas3_3.2.1+dfsg-1_amd64.deb

RUN wget http://mirrors.kernel.org/ubuntu/pool/universe/c/clapack/libcblas-dev_3.2.1+dfsg-1_amd64.deb && \
    dpkg -i libcblas-dev_3.2.1+dfsg-1_amd64.deb

RUN wget http://ftp.us.debian.org/debian/pool/main/c/clapack/libclapack3_3.2.1+dfsg-1_amd64.deb  && \
    dpkg -i libclapack3_3.2.1+dfsg-1_amd64.deb

RUN wget http://ftp.us.debian.org/debian/pool/main/c/clapack/libclapack-dev_3.2.1+dfsg-1_amd64.deb && \
    dpkg -i libclapack-dev_3.2.1+dfsg-1_amd64.deb

RUN wget https://mirror.kku.ac.th/ubuntu/ubuntu/pool/main/l/lapack/libtmglib3_3.7.1-1_amd64.deb && \
    dpkg -i libtmglib3_3.7.1-1_amd64.deb

RUN wget http://ftp.us.debian.org/debian/pool/main/l/lapack/libtmglib-dev_3.7.1-1_amd64.deb && \
    dpkg -i libtmglib-dev_3.7.1-1_amd64.deb

RUN git clone https://github.com/hpgl/hpgl.git

RUN cd hpgl/src/ && \
    bash -c "source activate python2 && scons -j 2"

RUN cd hpgl/src/ && \
    bash -c "source activate python2 && python2 setup.py install"

RUN rm -rf hpgl \
    scons-2.5.0* \
    libf2c2_20090411-2_amd64.deb \
    libf2c2-dev_20090411-2_amd64.deb \
    libtmglib3_3.7.1-1_amd64.deb \
    libtmglib-dev_3.7.1-1_amd64.deb \
    libcblas3_3.2.1+dfsg-1_amd64.deb \
    libcblas-dev_3.2.1+dfsg-1_amd64.deb \
    libclapack3_3.2.1+dfsg-1_amd64.deb \
    libclapack-dev_3.2.1+dfsg-1_amd64.deb

USER $NB_USER

这 运行 很顺利,我可以 运行 Docker 容器并启动笔记本,但是当我在 Python 中导入 HPGL 时,我得到了这个错误不知道发生了什么或如何解决这个问题:

---------------------------------------------------------------------------
OSError                                   Traceback (most recent call last)
<ipython-input-1-604a7d0744ab> in <module>()
----> 1 import geo_bsd

/opt/conda/envs/python2/lib/python2.7/site-packages/HPGL_BSD-0.9.9-py2.7.egg/geo_bsd/__init__.py in <module>()
      2 
      3 
----> 4 from geo import *
      5 from sgs import sgs_simulation
      6 from sis import sis_simulation

/opt/conda/envs/python2/lib/python2.7/site-packages/HPGL_BSD-0.9.9-py2.7.egg/geo_bsd/geo.py in <module>()
      3 import ctypes as C
      4 
----> 5 from hpgl_wrap import _HPGL_SHAPE, _HPGL_CONT_MASKED_ARRAY, _HPGL_IND_MASKED_ARRAY, _HPGL_UBYTE_ARRAY, _HPGL_FLOAT_ARRAY, _HPGL_OK_PARAMS, _HPGL_SK_PARAMS, _HPGL_IK_PARAMS, _HPGL_MEDIAN_IK_PARAMS, __hpgl_cov_params_t, __hpgl_cockriging_m1_params_t, __hpgl_cockriging_m2_params_t, _hpgl_so
      6 from hpgl_wrap import hpgl_output_handler, hpgl_progress_handler
      7 

/opt/conda/envs/python2/lib/python2.7/site-packages/HPGL_BSD-0.9.9-py2.7.egg/geo_bsd/hpgl_wrap.py in <module>()
    144         _hpgl_so = NC.load_library('hpgl_d', __file__)
    145 else:
--> 146         _hpgl_so = NC.load_library('hpgl', __file__)
    147 
    148 _hpgl_so.hpgl_set_output_handler.restype = None

/opt/conda/envs/python2/lib/python2.7/site-packages/numpy/ctypeslib.pyc in load_library(libname, loader_path)
    148             if os.path.exists(libpath):
    149                 try:
--> 150                     return ctypes.cdll[libpath]
    151                 except OSError:
    152                     ## defective lib file

/opt/conda/envs/python2/lib/python2.7/ctypes/__init__.pyc in __getitem__(self, name)
    435 
    436     def __getitem__(self, name):
--> 437         return getattr(self, name)
    438 
    439     def LoadLibrary(self, name):

/opt/conda/envs/python2/lib/python2.7/ctypes/__init__.pyc in __getattr__(self, name)
    430         if name[0] == '_':
    431             raise AttributeError(name)
--> 432         dll = self._dlltype(name)
    433         setattr(self, name, dll)
    434         return dll

/opt/conda/envs/python2/lib/python2.7/ctypes/__init__.pyc in __init__(self, name, mode, handle, use_errno, use_last_error)
    360 
    361         if handle is None:
--> 362             self._handle = _dlopen(self._name, mode)
    363         else:
    364             self._handle = handle

OSError: /usr/lib/libf2c.so.2: undefined symbol: MAIN__

编辑 1:

显然@Jean-François Fabre Here! 指出了这个非常相似的问题。在那里,问题与文件 libf2c.so 相关,并且是这样解决的:

rm /usr/lib/libf2c.so && ln -s /usr/lib/libf2c.a /usr/lib/libf2c.so

此解决方案由@p929 在同一线程中解释:

What it does is in fact is to delete the dynamic library and create an alias to the static library.

现在,我知道我遇到了同样的问题,但文件不同 (/usr/lib/libf2c.so.2)。解决方案是 "delete the dynamic library and create an alias to the static library"。我尝试使用相同的静态库 /usr/lib/libf2c.a 但没有成功。

解决方法:

安装时把动态库改成静态库,终于解决了问题。 HPGL 是使用 scons 构建的。来自 scons 网站:

SCons is an Open Source software construction tool (...) Configuration files are Python scripts

所以我在 hpgl/src 中编辑了 SConstruct 文件,然后调用 scons 构建 HPGL。

来自 hpgl/src 的原始 SConstruct 文件:

env = Environment(
    CPPDEFINES = cl_defines,
    CPPPATH = [ 
#       '/opt/boost_1_38_src/',
        'tnt_126',
        'geo_bsd/hpgl',
        'CLAPACK-3.1.1.1/INCLUDE' ],
    LIBS = ['stdc++', 'libgomp', 'pthread', 'lapack', 'f2c', 'tmglib', 'blas'],
    LIBPATH =  ['CLAPACK-3.1.1.1'], 
    )

我将列表 LIBS 更改为:

LIBS = ['stdc++', 'libgomp', 'pthread', 'lapack', File('/usr/lib/libf2c.a'), 'tmglib', 'blas'],

此解决方案由@BenG 在 this thread 中提出。

这样scons传递给我们想要的libf2c静态库的g++。部分构建:

g++ -o geo_bsd/_cvariogram.so -shared temp/release/geo_bsd/_cvariogram/ellipsoid.os temp/release/geo_bsd/_cvariogram/stack_layers.os temp/release/geo_bsd/_cvariogram/variograms.os -LCLAPACK-3.1.1.1 -lstdc++ -lgomp -lpthread -llapack /usr/lib/libf2c.a -ltmglib -lblas  

您是否尝试过将 LIBS 中的名称从 'libf2c' 更改为 'f2c'?