waf check_python_headers失败,并通过pyenv安装了python

问题描述

我正在尝试使用waf build tool构建项目。 检查python标头时,在配置步骤中构建失败。

我将问题缩小到我的wscript的最小示例:

int findroom(string roomName) {
    for (int i = 0; i < 1; i++) {
        if (room[i].room_name == roomName) {
            cout << room[i].room_name;
        }

        return 0;
    }
}

我使用在pyenv上在Ubuntu 20.04上安装的python版本(3.6.12和3.7.9)。

我这样运行,但失败并出现我无法理解的错误

def options(ctx):
        ctx.load('compiler_c')

def configure(ctx):
    ctx.load('compiler_c python')
    ctx.check_python_version((2,7,0))
    if int(ctx.env.PYTHON_VERSION[0]) == 2:
        print ('→ Configuring for python2')
    else:
        print ('→ Configuring for python3')
    ctx.check_python_headers(features='pyext')
$ python waf configure
Setting top to                           : /home/myuser/waf-test
Setting out to                           : /home/myuser/waf-test/build
Checking for 'gcc' (C compiler)          : /usr/bin/gcc
Checking for program 'python'            : /home/myuser/.pyenv/versions/3.7.9/bin/python
Checking for python version >= 2.7.0     : 3.7.9
→ Configuring for python3
python-config                            : /home/myuser/.pyenv/versions/3.7.9/bin/python-config
Asking python-config for pyext '--cflags --libs --ldflags' flags : yes
Testing pyext configuration                                      : Could not build python extensions
The configuration Failed
(complete log in /home/myuser/waf-test/build/config.log)

请注意,这个问题在pyenv也安装的python 3.8.6中没有出现。我可以没有错误地进行配置。

我的问题:pyenv中的python版本怎么可能因waf检查在一个版本而不在另一个版本中失败而有所不同? 由于我只是使用$ tail -n 20 build/config.log [1/2] Compiling build/.conf_check_d3b505aa7ab58576b6d76a2fc3091b1f/test.c ['/usr/bin/gcc','-fPIC','-g','-fwrapv','-O3','-I../../../../.pyenv/versions/3.7.9/include/python3.7m','-DPYTHONDIR="/usr/local/lib/python3.7/site-packages"','-DPYTHONARCHDIR="/usr/local/lib/python3.7/site-packages"','-DNDEBUG','../test.c','-c','-o/home/myuser/waf-test/build/.conf_check_d3b505aa7ab58576b6d76a2fc3091b1f/testbuild/test.c.1.o'] [2/2] Linking build/.conf_check_d3b505aa7ab58576b6d76a2fc3091b1f/testbuild/testprog.cpython-37m-x86_64-linux-gnu.so ['/usr/bin/gcc','-shared','test.c.1.o','-o/home/myuser/waf-test/build/.conf_check_d3b505aa7ab58576b6d76a2fc3091b1f/testbuild/testprog.cpython-37m-x86_64-linux-gnu.so','-Wl,-Bstatic',-Bdynamic','-L/home/myuser/.pyenv/versions/3.7.9/lib/python3.7/config-3.7m-x86_64-linux-gnu','-L/home/myuser/.pyenv/versions/3.7.9/lib','-lpython3.7m','-lcrypt','-lpthread','-ldl','-lutil','-lm','-lm'] err: /usr/bin/ld: /home/myuser/.pyenv/versions/3.7.9/lib/python3.7/config-3.7m-x86_64-linux-gnu/libpython3.7m.a(pylifecycle.o): relocation R_X86_64_PC32 against symbol `Py_VerboseFlag' can not be used when making a shared object; recompile with -fPIC /usr/bin/ld: final link Failed: bad value collect2: error: ld returned 1 exit status from /home/myuser/waf-test: Test does not build: Traceback (most recent call last): File "/home/myuser/waf-test/.waf3-2.0.20-36f5354d605298f6a89c09e0c7ef6c1d/waflib/Configure.py",line 335,in run_build bld.compile() File "/home/myuser/waf-test/.waf3-2.0.20-36f5354d605298f6a89c09e0c7ef6c1d/waflib/Build.py",line 176,in compile raise Errors.BuildError(self.producer.error) waflib.Errors.BuildError: Build Failed -> task in 'testprog' Failed with exit status 1 (run with -v to display more information) Could not build python extensions from /home/myuser/waf-test: The configuration Failed 安装版本,因此我需要在安装中进行哪些更改以使构建成功?

解决方法

好吧,错误是,在创建测试程序以检查pyext是否正确设置时,编译器会抱怨pylifecycle.o中包含的libpython3.7m.a是不可重定位的事实,即未使用-fPIC标志进行编译。

由于waf生成的代码片段是使用-fPIC编译的,因此问题似乎在于pylifecycle.o中的libpython3.7m.a没有使用-fPIC进行编译,这是有道理的在静态库中。也许问题在于它使用.a存档库而不是共享对象一个,即.so

检查您是否具有libpython的共享对象版本,即libpython3.7m.so

相关问答

Selenium Web驱动程序和Java。元素在(x,y)点处不可单击。其...
Python-如何使用点“。” 访问字典成员?
Java 字符串是不可变的。到底是什么意思?
Java中的“ final”关键字如何工作?(我仍然可以修改对象。...
“loop:”在Java代码中。这是什么,为什么要编译?
java.lang.ClassNotFoundException:sun.jdbc.odbc.JdbcOdbc...