安装libmemcached时gcc失败,退出状态1

2 投票
1 回答
3003 浏览
提问于 2025-04-17 03:33

在尝试按照 http://code.google.com/p/python-libmemcached/ 上的说明进行操作时,我在第三步(“python setup.py install”)遇到了问题。

    (gigmash_venv)m:python-libmemcached matthewparrilla$ python setup.py build
    running build
    running build_py
    creating build
    creating build/lib.macosx-10.3-fat-2.7
    copying cmemcached.py -> build/lib.macosx-10.3-fat-2.7
    running build_ext
    building 'cmemcached_imp' extension
    creating build/temp.macosx-10.3-fat-2.7
    gcc-4.0 -fno-strict-aliasing -fno-common -dynamic -isysroot /Developer/SDKs/MacOSX10.4u.sdk -arch ppc -arch i386 -g -O2 -DNDEBUG -g -O3 -I/Library/Frameworks/Python.framework/Versions/2.7/include/python2.7 -c cmemcached_imp.c -o build/temp.macosx-10.3-fat-2.7/cmemcached_imp.o
    powerpc-apple-darwin9-gcc-4.0.1: cmemcached_imp.c: No such file or directory
    powerpc-apple-darwin9-gcc-4.0.1: no input files
    i686-apple-darwin9-gcc-4.0.1: cmemcached_imp.c: No such file or directory
    i686-apple-darwin9-gcc-4.0.1: no input files
    lipo: can't figure out the architecture type of: /var/folders/0o/0oHT3RmJF80rpIJtdbegzE+++TI/-Tmp-//cc9xQqQ6.out
    error: command 'gcc-4.0' failed with exit status 1

我对这是什么意思或者该怎么做几乎一无所知。我电脑上有多个版本的gcc(4.0和4.2),通过谷歌搜索我了解到这可能会有影响。除此之外我完全迷失了方向。

提前谢谢你们。

[编辑:在按照@phihag的指示操作后]

我现在收到了一个完全不同但仍然令人困惑的错误:

    (gigmash_venv)m:python-libmemcached matthewparrilla$ python setup.py build
    running build
    running build_py
    running build_ext
    building 'cmemcached_imp' extension
    gcc-4.0 -fno-strict-aliasing -fno-common -dynamic -isysroot /Developer/SDKs/MacOSX10.4u.sdk -arch ppc -arch i386 -g -O2 -DNDEBUG -g -O3 -I/Library/Frameworks/Python.framework/Versions/2.7/include/python2.7 -c cmemcached_imp.c -o build/temp.macosx-10.3-fat-2.7/cmemcached_imp.o
    cmemcached_imp.c:237:36:cmemcached_imp.c:237:36: error:  error: libmemcached/memcached.h: No such file or directory
    libmemcached/memcached.h: No such file or directory
    In file included from cmemcached_imp.c:238:
    split_mc.h:14: warning: ‘struct memcached_st’ declared inside parameter list
    split_mc.h:14: warning: its scope is only this definition or declaration, which is probably not what you want
    split_mc.h:17: warning: ‘struct memcached_st’ declared inside parameter list
    In file included from cmemcached_imp.c:238:
    split_mc.h:14: warning: ‘struct memcached_st’ declared inside parameter list
    (and this goes on for many many more lines)...

1 个回答

4

这个错误发生是因为文件 cmemcached_imp.c 不在这里,但在这个步骤中必须编译它。

首先,打开文件 cmemcached_imp.pyx,在第506行修正一个拼写错误。原本是

sys.stderr.write("[cmemcached]%s only support string: %s" % (cmd, key))

,应该改成

sys.stderr.write("[cmemcached]%s only support string: %s" % (cmd, keys))

然后,安装 cython,并执行

$ cython cmemcached_imp.pyx

cython 会默默地生成文件 cmemcached_imp.c

虽然这样可以解决眼前的错误,但你可能还需要在 setup.py 中把

ext_modules=[Extension('cmemcached_imp',
            ['cmemcached_imp.pyx', 'split_mc.c'],

替换成

ext_modules=[Extension('cmemcached_imp',
            ['cmemcached_imp.c', 'split_mc.c'],

关于这个修改:

如果你严格按照说明操作,你还需要在本地目录中有 libmemcached。执行

$ ln -s $(pwd)/../libmemcached-0.40/libmemcached

在 python-libmemcached 中可以做到这一点。

撰写回答