首页 > 解决方案 > 导入python包时GSL未定义符号

问题描述

当我尝试导入我下载到 python 代码中的 python 包时,出现错误: Traceback (most recent call last): File "<stdin>", line 1, in <module> File "SZpack.py", line 15, in <module> import _SZpack ImportError: /home/eitanrapa/.local/lib/python2.7/site-packages/_SZpack.so: undefined symbol: gsl_interp_cspline

该包使用 C++,但它具有 python 绑定。当我尝试导入 python 绑定时,问题就来了。我已经尝试重新安装 GSL。请帮助我已经坚持了一段时间。

这是软件包的 README 文件:

INSTALLATION:

To compile the code follow the following steps:

(i) in 'Makefile.in' set 'CC' to the C++ compiler that should be used. 'CXXFLAGS' might have to 
    be adjusted accordingly.

(ii) The variables 'GSL_INC_PATH' and 'GSL_LIB_PATH' have to be set to the directories that host  
     the include-files and lib of the GSL-library, respectively. Also the name ('GSL=gsl') of the 
     GSL-lib should be adjusted, if necessary. In some cases it may be required to also link 
     the library 'libgslcblas.a'. 

(iii) type 'make' to compile the code. This creates the executable 'run_SZpack' and the 
      library 'libSZpack.a'

(iv)  type 'make SZpack.py' to compile python bindings. This creates 'SZpack.py'. SWIG is needed to 
      compile the 'SZpack.py'. Also, several SWIG specific warnings might appear, however, they did
      not cause any problems. 

To clean up type 'make clean' or 'make tidy', as well as 'make cleanall', 'make cleanallDEV' and
'make cleanpy' (see 'Makefile' for difference)

另外,这是我的makefile:

#===============================================================================
# choose c++ compiler & flags
#===============================================================================
CC= g++
CXXFLAGS = -Wall -pedantic -O2 -fPIC

#CC= icpc
#CXXFLAGS = -Wall -O2 -fPIC

#===============================================================================
# linker flags
#===============================================================================
LXXFLAGS =

#===============================================================================
# GSL lib
#===============================================================================
GSL          = gsl
GSL_INC_PATH = /usr/local/include/
GSL_LIB_PATH = /usr/local/lib/
#GSL_INC_PATH = /opt/local/include/
#GSL_LIB_PATH = /opt/local/lib/
LIBSGSL      = -L$(GSL_LIB_PATH) -l$(GSL) -lgslcblas

#===============================================================================
#===============================================================================
#===============================================================================
#
# below normally no changes should be necessary...
#
#===============================================================================
#===============================================================================
#===============================================================================


#===============================================================================
# directory Development-libs
#===============================================================================
DEV_DIR = ./Development
SRC_DIR = ./src
INC_DIR = ./include

#===============================================================================
# passing SZpack path on to the compiler
#===============================================================================
CXXFLAGSLOC = $(CXXFLAGS) -D SZPACKPATH=\"$(PWD)/\"

#===============================================================================
# Required external libs
#===============================================================================
LIBS    = $(LIBSGSL) -lm
#===============================================================================
# object files
#===============================================================================
OBJSDEV = $(DEV_DIR)/Simple_routines/Relativistic_MB.o \
          $(DEV_DIR)/Simple_routines/nPl_derivatives.o \
          $(DEV_DIR)/Simple_routines/routines.o \
          $(DEV_DIR)/Integration/Patterson.o \
          $(DEV_DIR)/Integration/Integration_routines.GSL.o \
          $(DEV_DIR)/Integration/Chebyshev_Int.o \
       
OBJSLIB = $(SRC_DIR)/SZ_Integral.5D.o \
          $(SRC_DIR)/SZ_Integral.3D.o \
          $(SRC_DIR)/SZ_asymptotic.o \
          $(SRC_DIR)/SZ_CNSN_basis.o \
          $(SRC_DIR)/SZ_CNSN_basis.opt.o

OBJS = $(OBJSDEV) $(OBJSLIB) SZpack.o

#===============================================================================
# program 
#===============================================================================

all: lib bin

bin: run_SZpack

lib: SZpacklib

run_SZpack:  $(OBJS) run_SZpack.o
       @echo "\n Linking run_SZpack binary\n"
       $(CC) $(LXXFLAGS) $(OBJS) run_SZpack.o $(LIBS) -o run_SZpack

SZpacklib: $(OBJS)
       @echo "\n Creating SZpack library\n"
       ar rvs ./libSZpack.a $?
         
#===============================================================================
# rules
#===============================================================================

INC_PATH = -I$(DEV_DIR)/Definitions \
       -I$(DEV_DIR)/Integration \
       -I$(DEV_DIR)/Simple_routines \
       -I$(INC_DIR) \
       -I$(GSL_INC_PATH) -I.

.cpp.o:
       @echo "Producing object-file $@"
       $(CC) $(CXXFLAGSLOC) $(INC_PATH) -c $< -o $@

libSZpack.a:
       make lib;

#===============================================================================

python绑定是用这个makefile编译的:

#===================================================================================================
# rules 
#===================================================================================================

all: clean SZpack.py

SZpack.py: libSZpack.a
         @echo "\n Creating SZpack Python routines\n" 
         python setup.py build
         python setup.py install --user
         
libSZpack.a:
         cd ../; make lib;
         
clean:
         rm -rf build
         rm -f SZpack.py SZpack.pyc SZpack_wrap.cpp *.pyc
         
cleanall: clean
         cd ..; make tidy;
          
#===================================================================================================
#===================================================================================================

标签: pythongsl

解决方案


推荐阅读