pyenv:编译模块

pyenv: compiling a module

我是 pyenv 的新手,现在正在使用它,所以我可以同时拥有 Python 3.7(系统/默认)和 Python 3.6.5(与尚不支持 3.7 的 TensorFlow 兼容) ).

我使用

安装了 3.6.5
pyenv install -v 3.6.5

我想使用的 TensorFlow 存储库在这方面运行良好。

这个 repo 将是一个更大项目的一部分。该项目包含另一个 repo https://github.com/argman/EAST,它需要在 lanms 文件夹中编译一些 C++ 代码。

当我 运行 制作 lanms 时,我得到:

clang: error: linker command failed with exit code 1 (use -v to see invocation)
make: *** [adaptor.so] Error 1

我试过

PYTHON_CONFIGURE_OPTS="--enable-shared CC=clang" pyenv install -v 3.6.5

这是我通过谷歌搜索找到的,但到目前为止没有任何效果。

注意:lanms/make 在 Python 3.7.

下工作正常

对于知道的人来说,这似乎是一件很简单的事情。如果有人有想法,请帮忙。谢谢

make 的完整输出如下:

Chandrachuds-MacBook-Pro:lanms Chandrachud$ make
find: -xtype: unknown primary or operator
c++ -o adaptor.so -I include  -std=c++11 -O3 -I/Users/Chandrachud/.pyenv/versions/3.6.5/include/python3.6m -I/Users/Chandrachud/.pyenv/versions/3.6.5/include/python3.6m -Wno-unused-result -Wsign-compare -Wunreachable-code -DNDEBUG -g -fwrapv -O3 -Wall -Wstrict-prototypes -L/Users/Chandrachud/.pyenv/versions/3.6.5/lib/python3.6/config-3.6m-darwin -lpython3.6m -lintl -ldl -framework CoreFoundation -Wl,-stack_size,1000000 -framework CoreFoundation adaptor.cpp include/clipper/clipper.cpp --shared -fPIC
adaptor.cpp:53:1: warning: 'pybind11_init' is deprecated: PYBIND11_PLUGIN is deprecated, use PYBIND11_MODULE [-Wdeprecated-declarations]
PYBIND11_PLUGIN(adaptor) {
^
include/pybind11/common.h:232:20: note: expanded from macro 'PYBIND11_PLUGIN'
            return pybind11_init();                                            \
                   ^
adaptor.cpp:53:1: note: 'pybind11_init' has been explicitly marked deprecated here
include/pybind11/common.h:216:5: note: expanded from macro 'PYBIND11_PLUGIN'
    PYBIND11_DEPRECATED("PYBIND11_PLUGIN is deprecated, use PYBIND11_MODULE")  \
    ^
include/pybind11/common.h:80:54: note: expanded from macro 'PYBIND11_DEPRECATED'
#  define PYBIND11_DEPRECATED(reason) __attribute__((deprecated(reason)))
                                                     ^
1 warning generated.
include/clipper/clipper.cpp:3665:13: warning: unused variable 'firstLeft' [-Wunused-variable]
    OutRec* firstLeft = ParseFirstLeft(outRec->FirstLeft);
            ^
1 warning generated.
ld: warning: text-based stub file /System/Library/Frameworks//CoreFoundation.framework/CoreFoundation.tbd and library file /System/Library/Frameworks//CoreFoundation.framework/CoreFoundation are out of sync. Falling back to library file for linking.
ld: warning: text-based stub file /System/Library/Frameworks//CoreFoundation.framework/CoreFoundation.tbd and library file /System/Library/Frameworks//CoreFoundation.framework/CoreFoundation are out of sync. Falling back to library file for linking.
ld: -stack_size option can only be used when linking a main executable
clang: error: linker command failed with exit code 1 (use -v to see invocation)
make: *** [adaptor.so] Error 1

我在这里看到两个主要问题:

  1. find 使用的是 xtype 而不是 type,Mac 不支持后者。您应该能够更改 xtype 以在 Makefile 中键入。例如:

    DEPS = lanms.h $(shell find include -type f)
    
  2. 这个错误:

    ld: -stack_size option can only be used when linking a main executable
    

    您将 -Wl,-stack_size,1000000 传递给 clang,它告诉它生成具有更大堆栈的可执行文件。但是,clang 只是创建一个 .so 文件,无法控制堆栈的大小。

    之所以出现 -Wl,-stack_size,1000000 是因为这一行:

    LDFLAGS = $(shell python3-config --ldflags)
    

    python3-config --ldflags 这样做的原因是因为 Python 最近的一个错误:https://bugs.python.org/issue34960

    因此,您可以等到 Python 修复此问题,或者您可以采取解决方法:运行 python3-config --ldflags。将输出粘贴到 LDFLAGS 行中,减去 -Wl,-stack_size,1000000 部分。然后,您应该能够构建它。

如果有人在阅读本文时遇到类似问题,这里是 Makefile 的相关部分:

LDFLAGS0 = $(shell python3-config --ldflags) 

UNAME = $(shell uname)

ifeq ($(UNAME), Darwin)
    LDSTACK = -Wl,-stack_size,1000000
    LDFLAGS = $(filter-out $(LDSTACK), $(LDFLAGS0))
    DEPS = lanms.h $(shell find include -type f)
else
    LDFLAGS = $(LDFLAGS0)
    DEPS = lanms.h $(shell find include -xtype f)
endif