2015年6月20日星期六

cdec/python 关于运行 python setup.py build 的错误

g++ -pthread -shared build/temp.linux-x86_64-2.7/cdec/_cdec.o -L../decoder -L../utils -L../mteval -L../training/utils -L../klm/lm -L../klm/util -L../klm/util/double-conversion -L../klm/search -lcdec -lutils -lmteval -ltraining_utils -lklm -lklm_util -lklm_util_double -lksearch -ldl -lrt -lboost_program_options -lboost_regex-mt -lboost_serialization-mt -lboost_system -lboost_filesystem-mt -lz -lbz2 -llzma -o build/lib.linux-x86_64-2.7/cdec/_cdec.so -L/usr/local/lib -Wl,-R,/usr/local/lib -L/usr/local/lib -Wl,-R,/usr/local/lib -L/usr/local/lib -Wl,-R,/usr/local/lib -L/usr/local/lib -Wl,-R,/usr/local/lib -L/usr/local/lib -Wl,-R,/usr/local/lib /usr/bin/ld: /usr/local/lib/libbz2.a(bzlib.o): relocation R_X86_64_32S against `BZ2_crc32Table' can not be used when making a shared object; recompile with -fPIC /usr/local/lib/libbz2.a: could not read symbols: Bad value collect2: error: ld returned 1 exit status error: command 'g++' failed with exit status 1 

解决方法: 用一个较新版本cdec/python/setup.py替换掉原版本(cdec-2014-06-15)的cdec-2014-06-15/python/setup.py cdec-2014-06-15/python/setup.py的内容是:
 
from distutils.core import setup
from distutils.extension import Extension
import re

INC = ['..', 'cdec/', '../decoder', '../utils', '../mteval']
LIB = ['../decoder', '../utils', '../mteval', '../training/utils', '../klm/lm', '../klm/util', '../klm/util/double-conversion', '../klm/search']

# Set automatically by configure
LIBS = re.findall('-l([^\s]+)', '-ldl -lrt  -lboost_program_options -lboost_regex-mt -lboost_serialization-mt -lboost_system -lboost_filesystem-mt  -lz -lbz2 -llzma')
CPPFLAGS = re.findall('-[^\s]+', '-DPIC   -pthread -DHAVE_CONFIG_H -DKENLM_MAX_ORDER=6 -std=gnu++11  -fPIC -g -O3')
LDFLAGS = re.findall('-[^\s]+', ' -L/usr/local/lib -Wl,-R,/usr/local/lib -L/usr/local/lib -Wl,-R,/usr/local/lib -L/usr/local/lib -Wl,-R,/usr/local/lib -L/usr/local/lib -Wl,-R,/usr/local/lib -L/usr/local/lib -Wl,-R,/usr/local/lib')

ext_modules = [
    Extension(name='cdec._cdec',
        sources=['cdec/_cdec.cpp'],
        include_dirs=INC,
        library_dirs=LIB,
        libraries=['cdec', 'utils', 'mteval', 'training_utils', 'klm', 'klm_util', 'klm_util_double', 'ksearch'] + LIBS,
        extra_compile_args=CPPFLAGS,
        extra_link_args=LDFLAGS),
    Extension(name='cdec.sa._sa',
        sources=['cdec/sa/_sa.cpp', 'cdec/sa/strmap.cc'],
        extra_compile_args=CPPFLAGS)
]

setup(
    name='cdec',
    ext_modules=ext_modules,
    packages=['cdec', 'cdec.sa']
)


较新版本的setup.py的内容


 
from distutils.core import setup
from distutils.extension import Extension
import re

INC = ['..', 'cdec/', '../decoder', '../utils', '../mteval']
LIB = ['../decoder', '../utils', '../mteval', '../training/utils', '../klm/lm', '../klm/util', '../klm/util/double-conversion', '../klm/search']

# Set automatically by configure
LIBS = re.findall('-l([^\s]+)', '-ldl -lrt  -lboost_program_options -lboost_regex-mt -lboost_serialization-mt -lboost_system -lboost_filesystem-mt  -lz -lbz2 -llzma')
CPPFLAGS = re.findall('-[^\s]+', '-DPIC  -I/home/jhli/local/include  -DHAVE_CONFIG_H -DKENLM_MAX_ORDER=6 -std=gnu++11  -fPIC -g -O3')
LDFLAGS = re.findall('-[^\s]+', ' -L/home/jhli/local/lib -Wl,-R,/home/jhli/local/lib -L/home/jhli/local/lib -Wl,-R,/home/jhli/local/lib -L/home/jhli/local/lib -Wl,-R,/home/jhli/local/lib -L/home/jhli/local/lib -Wl,-R,/home/jhli/local/lib -L/home/jhli/local/lib -Wl,-R,/home/jhli/local/lib')

ext_modules = [
    Extension(name='cdec._cdec',
        sources=['cdec/_cdec.cpp'],
        include_dirs=INC,
        library_dirs=LIB,
        libraries=['cdec', 'utils', 'mteval', 'training_utils', 'klm', 'klm_util', 'klm_util_double', 'ksearch'] + LIBS,
        extra_compile_args=CPPFLAGS,
        extra_link_args=LDFLAGS),
    Extension(name='cdec.sa._sa',
        sources=['cdec/sa/_sa.cpp', 'cdec/sa/strmap.cc'],
        extra_compile_args=CPPFLAGS)
]

setup(
    name='cdec',
    ext_modules=ext_modules,
    packages=['cdec', 'cdec.sa']
)

没有评论: