Voglio racchiudere un progetto di test contenente codice C++ e OpenMP con Cython e lo costruisco con distutils tramite un file setup.py
. Il contenuto del mio file è simile al seguente:Come dire a distutils di usare gcc?
from distutils.core import setup
from distutils.extension import Extension
from Cython.Build import cythonize
from Cython.Distutils import build_ext
modules = [Extension("Interface",
["Interface.pyx", "Parallel.cpp"],
language = "c++",
extra_compile_args=["-fopenmp"],
extra_link_args=["-fopenmp"])]
for e in modules:
e.cython_directives = {"embedsignature" : True}
setup(name="Interface",
cmdclass={"build_ext": build_ext},
ext_modules=modules)
La bandiera -fopenmp
viene utilizzato con gcc per compilare e Link contro OpenMP. Tuttavia, se ho appena invoco
cls ~/workspace/CythonOpenMP/src $ python3 setup.py build
questo flag non viene riconosciuto, perché il compilatore è clang:
running build
running build_ext
skipping 'Interface.cpp' Cython extension (up-to-date)
building 'Interface' extension
cc -Wno-unused-result -fno-common -dynamic -DNDEBUG -g -O3 -Wall -Wstrict-prototypes -I/usr/local/include -I/usr/local/opt/sqlite/include -I/usr/local/Cellar/python3/3.3.0/Frameworks/Python.framework/Versions/3.3/include/python3.3m -c Interface.cpp -o build/temp.macosx-10.8-x86_64-3.3/Interface.o -fopenmp
clang: warning: argument unused during compilation: '-fopenmp'
cc -Wno-unused-result -fno-common -dynamic -DNDEBUG -g -O3 -Wall -Wstrict-prototypes -I/usr/local/include -I/usr/local/opt/sqlite/include -I/usr/local/Cellar/python3/3.3.0/Frameworks/Python.framework/Versions/3.3/include/python3.3m -c Parallel.cpp -o build/temp.macosx-10.8-x86_64-3.3/Parallel.o -fopenmp
clang: warning: argument unused during compilation: '-fopenmp'
Parallel.cpp:24:10: warning: unknown pragma ignored [-Wunknown-pragmas]
#pragma omp parallel for
^
1 warning generated.
c++ -bundle -undefined dynamic_lookup -L/usr/local/lib -L/usr/local/opt/sqlite/lib build/temp.macosx-10.8-x86_64-3.3/Interface.o build/temp.macosx-10.8-x86_64-3.3/Parallel.o -o build/lib.macosx-10.8-x86_64-3.3/Interface.so -fopenmp
ld: library not found for -lgomp
clang: error: linker command failed with exit code 1 (use -v to see invocation)
error: command 'c++' failed with exit status 1
ho provato senza successo per specificare gcc:
cls ~/workspace/CythonOpenMP/src $ python3 setup.py build --compiler=g++-4.7
running build
running build_ext
error: don't know how to compile C/C++ code on platform 'posix' with 'g++-4.7' compiler
Come può Dico a distutils di usare gcc?
'os.environ [" CC "] =" g ++ - 4.7 " os.environ [" CXX " ] = "g ++ - 4.7" 'appena funzionante – clstaudt
Questo non funziona per me. Il mio problema è che 'setup.py' vuole usare' icc'. Quando imposto 'CC = gcc', prova a usare' gcc', ma continua ad usare gli argomenti della riga di comando appropriati per 'icc', tra cui' -fp-model strict' che 'gcc' non capisce, e abortisce. Quindi sembra che l'impostazione di 'CC' non sia il modo giusto per farlo. – amaurea
Distutils * non * controlla CXX, quindi l'impostazione potrebbe finire per confonderti. Potresti voler rimuovere il suggerimento per aggiungere "CXX" poiché è fuorviante. – SethMMorton