pyenv:编译模块

时间:2019-01-09 16:44:50

标签: makefile pyenv

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

我使用

安装了3.6.5
pyenv install -v 3.6.5

我想使用的TensorFlow回购在此上工作正常。

此仓库将是一个较大项目的一部分。该项目包括另一个仓库https://docs.microsoft.com/fr-fr/xamarin/xamarin-forms/app-fundamentals/custom-renderer/entry,该仓库需要在lanms文件夹中编译一些C ++代码。

当我运行lan make时,我得到:

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

2 个答案:

答案 0 :(得分: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部分。然后,您应该可以构建它。

答案 1 :(得分:1)

如果有人读到类似问题,这是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