Невозможно построить расширение Cython - PullRequest
0 голосов
/ 30 сентября 2019

Я пытаюсь построить расширение Python с помощью Cython со следующей структурой проекта:

include/
    algorithm/
        LessonplanScheduler.hpp
src/
    LessonplanScheduler.cpp
    GenAlgorithm.cpp
    GenAlgorithm.hpp
    LessonplanGenAlgorithm.cpp
    LessonplanGenAlgorithm.cpp
__init__.py
algorithm.pyx
LessonplanScheduler.pxd
setup.py

setup.py выглядит следующим образом:

from distutils.core import setup
from distutils.extension import Extension
from Cython.Build import cythonize

setup(
      name='Lessonplan scheduler algorithm',
      ext_modules=cythonize(
          [
              Extension(
                  name="algorithm",
                  include_dirs=["./include/algorithm"],
                  library_dirs=["./src"],
                  sources=["algorithm.pyx", "algorithm.cpp"],
              )
          ],
          language_level=3
      ),
      requires=['Cython'],
)

После запуска python ./setup.py build_ext --inplace, яя получаю папку build в корне проекта и algorithm.cpp также там. Но файл .so не создан из-за ошибок multiple definition:

Compiling algorithm.pyx because it changed.
[1/1] Cythonizing algorithm.pyx
running build_ext
building 'algorithm' extension
creating build
creating build/temp.linux-x86_64-3.7
gcc -pthread -Wno-unused-result -Wsign-compare -DNDEBUG -g -fwrapv -O3 -Wall -fPIC -I. -I./include/algorithm -I/usr/local/include/python3.7m -c algorithm.cpp -o build/temp.linux-x86_64-3.7/algorithm.o
gcc -pthread -Wno-unused-result -Wsign-compare -DNDEBUG -g -fwrapv -O3 -Wall -fPIC -I. -I./include/algorithm -I/usr/local/include/python3.7m -c algorithm.cpp -o build/temp.linux-x86_64-3.7/algorithm.o
creating build/lib.linux-x86_64-3.7
g++ -pthread -shared build/temp.linux-x86_64-3.7/algorithm.o build/temp.linux-x86_64-3.7/algorithm.o -L./src -L/usr/local/lib -lpython3.7m -o build/lib.linux-x86_64-3.7/algorithm.cpython-37m-x86_64-linux-gnu.so
/usr/bin/ld: build/temp.linux-x86_64-3.7/algorithm.o:(.bss+0x0): multiple definition of `__pyx_module_is_main_algorithm'; build/temp.linux-x86_64-3.7/algorithm.o:(.bss+0x0): first defined here
/usr/bin/ld: build/temp.linux-x86_64-3.7/algorithm.o: in function `PyInit_algorithm':
/backend/backend/algorithm/algorithm.cpp:1966: multiple definition of `PyInit_algorithm'; build/temp.linux-x86_64-3.7/algorithm.o:/backend/backend/algorithm/algorithm.cpp:1966: first defined here
collect2: error: ld returned 1 exit status
error: command 'g++' failed with exit status 1

Проблема, как я полагаю, содержится в файле algorithm.cpp, поэтому она, вероятно, вызвана неправильной конфигурацией сборки. Что я должен сделать, чтобы решить проблему, и как лучше всего построить проект?

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...