g++ 编译cpp程序 /usr/bin/ld: cannot find -lopencv_cudabgsegm....等问题

执行
g++ mtcnn_opencv.cpp -I /usr/local/opencv3.4.0/include -shared -o libmtcnndetection2.so -std=c++11 -fPIC pkg-config opencv --cflags --libs
出现如下问题:
/usr/bin/ld: cannot find -lopencv_cudabgsegm
/usr/bin/ld: cannot find -lopencv_cudaobjdetect
/usr/bin/ld: cannot find -lopencv_cudastereo
/usr/bin/ld: cannot find -lopencv_dnn
/usr/bin/ld: cannot find -lopencv_ml
/usr/bin/ld: cannot find -lopencv_shape
/usr/bin/ld: cannot find -lopencv_stitching
/usr/bin/ld: cannot find -lopencv_cudafeatures2d
/usr/bin/ld: cannot find -lopencv_superres
/usr/bin/ld: cannot find -lopencv_cudacodec
/usr/bin/ld: cannot find -lopencv_videostab
/usr/bin/ld: cannot find -lopencv_cudaoptflow
/usr/bin/ld: cannot find -lopencv_cudalegacy
/usr/bin/ld: cannot find -lopencv_calib3d
/usr/bin/ld: cannot find -lopencv_features2d
/usr/bin/ld: cannot find -lopencv_highgui
/usr/bin/ld: cannot find -lopencv_videoio
/usr/bin/ld: cannot find -lopencv_photo
/usr/bin/ld: cannot find -lopencv_imgcodecs
/usr/bin/ld: cannot find -lopencv_cudawarping
/usr/bin/ld: cannot find -lopencv_cudaimgproc
/usr/bin/ld: cannot find -lopencv_cudafilters
/usr/bin/ld: cannot find -lopencv_video
/usr/bin/ld: cannot find -lopencv_objdetect
/usr/bin/ld: cannot find -lopencv_imgproc
/usr/bin/ld: cannot find -lopencv_flann
/usr/bin/ld: cannot find -lopencv_cudaarithm
/usr/bin/ld: cannot find -lopencv_core
/usr/bin/ld: cannot find -lopencv_cudev
collect2: error: ld returned 1 exit status
第一步解决:
执行
sudo apt-get install libopencv-dev
解决非cuda的问题(/usr/bin/ld: cannot find -lopencv_dnn)除外
/usr/bin/ld: cannot find -lopencv_cudabgsegm
/usr/bin/ld: cannot find -lopencv_cudaobjdetect
/usr/bin/ld: cannot find -lopencv_cudastereo
/usr/bin/ld: cannot find -lopencv_dnn
/usr/bin/ld: cannot find -lopencv_cudafeatures2d
/usr/bin/ld: cannot find -lopencv_cudacodec
/usr/bin/ld: cannot find -lopencv_cudaoptflow
/usr/bin/ld: cannot find -lopencv_cudalegacy
/usr/bin/ld: cannot find -lopencv_cudawarping
/usr/bin/ld: cannot find -lopencv_cudaimgproc
/usr/bin/ld: cannot find -lopencv_cudafilters
/usr/bin/ld: cannot find -lopencv_cudaarithm
/usr/bin/ld: cannot find -lopencv_cudev
第二步解决:
指定库路径 -L指定路径 -L /usr/local/opencv3.4.0/lib
g++ mtcnn_opencv.cpp -I /usr/local/opencv3.4.0/include -L /usr/local/opencv3.4.0/lib -shared -o libmtcnndetection2.so -std=c++ 11 -fPIC pkg-config opencv --cflags --libs
【g++ 编译cpp程序 /usr/bin/ld: cannot find -lopencv_cudabgsegm....等问题】成功生成动态链接库so文件

    推荐阅读