Search code examples
makefilepyenv

pyenv: compiling a module


I am new to pyenv, using it now so I can have both Python 3.7 (system / default) and Python 3.6.5 (for compatibility with TensorFlow which does not yet support 3.7).

I installed 3.6.5 using

pyenv install -v 3.6.5

The TensorFlow repo I wanted to use works fine on this.

This repo will be part of a larger project. This project includes another repo https://github.com/argman/EAST, which requires compilation of some C++ code in the lanms folder.

When I run make in lanms, I get:

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

I tried things like

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

which I found by Googling, but so far nothing has worked.

Note: lanms/make works fine under Python 3.7.

This seems to be quite a simple thing for those who know. If anyone has an idea, please help. Thanks

Full output of make below:

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

Solution

  • I see two main issues here:

    1. find is using xtype rather than type, which is not supported on Mac. You should be able to change xtype to type in the Makefile. e.g:

      DEPS = lanms.h $(shell find include -type f)
      
    2. This error:

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

      You're passing -Wl,-stack_size,1000000 to clang, which tells it to make an executable with a larger stack. However, clang is only creating a .so file, which can't control how big the stack is.

      The reason -Wl,-stack_size,1000000 is in there is because of this line:

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

      The reason why python3-config --ldflags does this is because of a recent bug in Python: https://bugs.python.org/issue34960

      So, you could wait until Python fixes this, or you could do a workaround: Run python3-config --ldflags. Paste the output into the LDFLAGS line, minus the -Wl,-stack_size,1000000 part. Then, you should be able to build it.