如何将 makefile 重写为 distutils.core.Extension
How to rewrite a makefile to distutils.core.Extension
我有以下生成文件:
g++ -o OUTPUT runner.cpp main.cpp src/file1.cpp src/file2.cpp
-L/usr/local/cpp_gpu/lib
-lopencv_gapi -lopencv_stitching -lopencv_aruco -lopencv_bgsegm -lopencv_bioinspired -lopencv_ccalib -lopencv_cudabgsegm -lopencv_cudafeatures2d -lopencv_cudaobjdetect -lopencv_cudastereo -lopencv_dnn_objdetect -lopencv_dnn_superres -lopencv_dpm -lopencv_face -lopencv_freetype -lopencv_fuzzy -lopencv_hdf -lopencv_hfs -lopencv_img_hash -lopencv_intensity_transform -lopencv_line_descriptor -lopencv_mcc -lopencv_quality -lopencv_rapid -lopencv_reg -lopencv_rgbd -lopencv_saliency -lopencv_stereo -lopencv_structured_light -lopencv_phase_unwrapping -lopencv_superres -lopencv_surface_matching -lopencv_tracking -lopencv_highgui -lopencv_datasets -lopencv_text -lopencv_plot -lopencv_videostab -lopencv_cudaoptflow -lopencv_optflow -lopencv_cudalegacy -lopencv_videoio -lopencv_cudawarping -lopencv_xfeatures2d -lopencv_shape -lopencv_ml -lopencv_ximgproc -lopencv_video -lopencv_dnn -lopencv_xobjdetect -lopencv_objdetect -lopencv_calib3d -lopencv_imgcodecs -lopencv_features2d -lopencv_flann -lopencv_xphoto -lopencv_photo -lopencv_cudaimgproc -lopencv_cudafilters -lopencv_imgproc -lopencv_cudaarithm -lopencv_core -lopencv_cudev -ldl -lm -lpthread -lrt
-L/usr/local/cuda/lib64
-lcudart -lnppc -lnppial -lnppicc -lnppicom -lnppidei -lnppif -lnppig -lnppim -lnppist -lnppisu -lnppitc -lnpps -lcublas -lcudnn -lcufft
-I/usr/local/cpp_gpu/include/opencv4
我想将其重写为 distutils.core 的扩展,以便稍后可以在 Cython 设置中使用。 documentation 有点不清楚我应该怎么做。这是我到目前为止得到的(setup.py)。
includes_dirs = [numpy.get_include(), '/usr/local/cpp_gpu/lib', '/usr/local/cuda/lib64']
library_dirs = ['/usr/local/cpp_gpu/include/opencv4']
args = ['-Wno-cpp']
files = ["src/file1.cpp", "src/file2.cpp", "main.cpp", "OUTPUT.pyx"]
libraries = ['opencv_gapi', 'opencv_stitching', 'opencv_aruco', 'opencv_bgsegm', 'opencv_bioinspired', 'opencv_ccalib',
'opencv_cudabgsegm', 'opencv_cudafeatures2d', 'opencv_cudaobjdetect', 'opencv_cudastereo', 'opencv_dnn_objdetect',
'opencv_dnn_superres', 'opencv_dpm', 'opencv_face', 'opencv_freetype', 'opencv_fuzzy', 'opencv_hdf', 'opencv_hfs',
'opencv_img_hash', 'opencv_intensity_transform', 'opencv_line_descriptor', 'opencv_mcc', 'opencv_quality',
'opencv_rapid', 'opencv_reg', 'opencv_rgbd', 'opencv_saliency', 'opencv_stereo', 'opencv_structured_light',
'opencv_phase_unwrapping', 'opencv_superres', 'opencv_surface_matching', 'opencv_tracking', 'opencv_highgui',
'opencv_datasets', 'opencv_text', 'opencv_plot', 'opencv_videostab', 'opencv_cudaoptflow', 'opencv_optflow',
'opencv_cudalegacy', 'opencv_videoio', 'opencv_cudawarping', 'opencv_xfeatures2d', 'opencv_shape', 'opencv_ml',
'opencv_ximgproc', 'opencv_video', 'opencv_dnn', 'opencv_xobjdetect', 'opencv_objdetect', 'opencv_calib3d',
'opencv_imgcodecs', 'opencv_features2d', 'opencv_flann', 'opencv_xphoto', 'opencv_photo', 'opencv_cudaimgproc',
'opencv_cudafilters', 'opencv_imgproc', 'opencv_cudaarithm', 'opencv_core', 'opencv_cudev', 'dl', 'm', 'pthread', 'rt']
libraries += ['cudart', 'nppc', 'nppial', 'nppicc', 'nppicom', 'nppidei', 'nppif', 'nppig', 'nppim', 'nppist', 'nppisu',
'nppitc', 'npps', 'cublas', 'cudnn', 'cufft ']
ext_modules = [Extension(
"OUTPUT",
files,
language='c++',
include_dirs=includes_dirs,
library_dirs=library_dirs,
extra_compile_args=args,
libraries=libraries
)]
但是编译失败并显示错误消息(如果与 makefile 一起使用则工作正常):
src/file1.hpp:7:34: fatal error: opencv2/cudaarithm.hpp: No such file or directory
#include <opencv2/cudaarithm.hpp>
我发现了应该切换包含目录和库目录的问题:
includes_dirs = [numpy.get_include(), '/usr/local/cpp_gpu/include/opencv4']
library_dirs = ['/usr/local/cpp_gpu/lib', '/usr/local/cuda/lib64']
我有以下生成文件:
g++ -o OUTPUT runner.cpp main.cpp src/file1.cpp src/file2.cpp
-L/usr/local/cpp_gpu/lib
-lopencv_gapi -lopencv_stitching -lopencv_aruco -lopencv_bgsegm -lopencv_bioinspired -lopencv_ccalib -lopencv_cudabgsegm -lopencv_cudafeatures2d -lopencv_cudaobjdetect -lopencv_cudastereo -lopencv_dnn_objdetect -lopencv_dnn_superres -lopencv_dpm -lopencv_face -lopencv_freetype -lopencv_fuzzy -lopencv_hdf -lopencv_hfs -lopencv_img_hash -lopencv_intensity_transform -lopencv_line_descriptor -lopencv_mcc -lopencv_quality -lopencv_rapid -lopencv_reg -lopencv_rgbd -lopencv_saliency -lopencv_stereo -lopencv_structured_light -lopencv_phase_unwrapping -lopencv_superres -lopencv_surface_matching -lopencv_tracking -lopencv_highgui -lopencv_datasets -lopencv_text -lopencv_plot -lopencv_videostab -lopencv_cudaoptflow -lopencv_optflow -lopencv_cudalegacy -lopencv_videoio -lopencv_cudawarping -lopencv_xfeatures2d -lopencv_shape -lopencv_ml -lopencv_ximgproc -lopencv_video -lopencv_dnn -lopencv_xobjdetect -lopencv_objdetect -lopencv_calib3d -lopencv_imgcodecs -lopencv_features2d -lopencv_flann -lopencv_xphoto -lopencv_photo -lopencv_cudaimgproc -lopencv_cudafilters -lopencv_imgproc -lopencv_cudaarithm -lopencv_core -lopencv_cudev -ldl -lm -lpthread -lrt
-L/usr/local/cuda/lib64
-lcudart -lnppc -lnppial -lnppicc -lnppicom -lnppidei -lnppif -lnppig -lnppim -lnppist -lnppisu -lnppitc -lnpps -lcublas -lcudnn -lcufft
-I/usr/local/cpp_gpu/include/opencv4
我想将其重写为 distutils.core 的扩展,以便稍后可以在 Cython 设置中使用。 documentation 有点不清楚我应该怎么做。这是我到目前为止得到的(setup.py)。
includes_dirs = [numpy.get_include(), '/usr/local/cpp_gpu/lib', '/usr/local/cuda/lib64']
library_dirs = ['/usr/local/cpp_gpu/include/opencv4']
args = ['-Wno-cpp']
files = ["src/file1.cpp", "src/file2.cpp", "main.cpp", "OUTPUT.pyx"]
libraries = ['opencv_gapi', 'opencv_stitching', 'opencv_aruco', 'opencv_bgsegm', 'opencv_bioinspired', 'opencv_ccalib',
'opencv_cudabgsegm', 'opencv_cudafeatures2d', 'opencv_cudaobjdetect', 'opencv_cudastereo', 'opencv_dnn_objdetect',
'opencv_dnn_superres', 'opencv_dpm', 'opencv_face', 'opencv_freetype', 'opencv_fuzzy', 'opencv_hdf', 'opencv_hfs',
'opencv_img_hash', 'opencv_intensity_transform', 'opencv_line_descriptor', 'opencv_mcc', 'opencv_quality',
'opencv_rapid', 'opencv_reg', 'opencv_rgbd', 'opencv_saliency', 'opencv_stereo', 'opencv_structured_light',
'opencv_phase_unwrapping', 'opencv_superres', 'opencv_surface_matching', 'opencv_tracking', 'opencv_highgui',
'opencv_datasets', 'opencv_text', 'opencv_plot', 'opencv_videostab', 'opencv_cudaoptflow', 'opencv_optflow',
'opencv_cudalegacy', 'opencv_videoio', 'opencv_cudawarping', 'opencv_xfeatures2d', 'opencv_shape', 'opencv_ml',
'opencv_ximgproc', 'opencv_video', 'opencv_dnn', 'opencv_xobjdetect', 'opencv_objdetect', 'opencv_calib3d',
'opencv_imgcodecs', 'opencv_features2d', 'opencv_flann', 'opencv_xphoto', 'opencv_photo', 'opencv_cudaimgproc',
'opencv_cudafilters', 'opencv_imgproc', 'opencv_cudaarithm', 'opencv_core', 'opencv_cudev', 'dl', 'm', 'pthread', 'rt']
libraries += ['cudart', 'nppc', 'nppial', 'nppicc', 'nppicom', 'nppidei', 'nppif', 'nppig', 'nppim', 'nppist', 'nppisu',
'nppitc', 'npps', 'cublas', 'cudnn', 'cufft ']
ext_modules = [Extension(
"OUTPUT",
files,
language='c++',
include_dirs=includes_dirs,
library_dirs=library_dirs,
extra_compile_args=args,
libraries=libraries
)]
但是编译失败并显示错误消息(如果与 makefile 一起使用则工作正常):
src/file1.hpp:7:34: fatal error: opencv2/cudaarithm.hpp: No such file or directory
#include <opencv2/cudaarithm.hpp>
我发现了应该切换包含目录和库目录的问题:
includes_dirs = [numpy.get_include(), '/usr/local/cpp_gpu/include/opencv4']
library_dirs = ['/usr/local/cpp_gpu/lib', '/usr/local/cuda/lib64']