from setuptools import setup
from torch.utils.cpp_extension import CppExtension, BuildExtension

setup(
    name='video_capture_cpp',
    ext_modules=[
        CppExtension('video_capture_cpp', ['video_capture.cpp'],
                     extra_compile_args=[
                         '-I/home/lshi/Application/Anaconda/include',
                         '-I/home/lshi/Application/Anaconda/include/opencv/',
                         '-lopencv_cudacodec', '-lopencv_core','-lopencv_highgui', '-lopencv_imgproc',
                         '-L/home/lshi/Application/Anaconda/lib64/',
                     ]),
    ],
    cmdclass={
        'build_ext': BuildExtension
    })

When import video_capture_cpp
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ImportError: ..../video_capture_cpp.cpython-36m-x86_64-linux-gnu.so
undefined symbol: _ZN2cv6String10deallocateEv

and my video capture cpp
#include <torch/torch.h>
#include <string>
#include "opencv2/cudacodec.hpp"
#include <ctime>
#include <iostream>

using namespace std;
using namespace cv;
using namespace cv::cuda;

void video_capture(uchar *pointer, string video_path) {
    GpuMat *capture_frame;
    capture_frame->data = pointer;
    cv::Ptr<cudacodec::VideoReader> video_stream1 = cudacodec::createVideoReader(video_path);
    video_stream1->nextFrame(*capture_frame);
    int height = capture_frame->size().height;
    int width = capture_frame->size().width;
    int size[2] = {height, width};
    cout << height << width << endl;
}

PYBIND11_MODULE(TORCH_EXTENSION_NAME, m) {
    m.def("video_capture", &video_capture, "video_capture");
}