Issue 1:
[ 16%] Linking CXX executable ../../bin/example_phase_unwrapping_unwrap
cd /home/khurram/LIBRARIES/OPENCV34/opencv/build/modules/phase_unwrapping && /home/khurram/miniconda3/bin/cmake -E cmake_link_script CMakeFiles/example_phase_unwrapping_unwrap.dir/link.txt --verbose=1
/usr/bin/c++ -g -H -fsigned-char -W -Wall -Werror=return-type -Werror=non-virtual-dtor -Werror=address -Werror=sequence-point -Wformat -Werror=format-security -Wmissing-declarations -Wundef -Winit-self -Wpointer-arith -Wshadow -Wsign-promo -Wuninitialized -Winit-self -Wno-narrowing -Wno-delete-non-virtual-dtor -Wno-comment -fdiagnostics-show-option -Wno-long-long -pthread -fomit-frame-pointer -ffunction-sections -fdata-sections -msse -msse2 -msse3 -fvisibility=hidden -fvisibility-inlines-hidden -O3 -DNDEBUG -DNDEBUG -Wl,--gc-sections CMakeFiles/example_phase_unwrapping_unwrap.dir/samples/unwrap.cpp.o -o ../../bin/example_phase_unwrapping_unwrap -L/usr/local/cuda-9.0/lib64 -Wl,-rpath,/usr/local/cuda-9.0/lib64:/home/khurram/LIBRARIES/OPENCV34/opencv/build/lib ../../lib/libopencv_phase_unwrapping.so.4.0.0 ../../lib/libopencv_highgui.so.4.0.0 ../../lib/libopencv_videoio.so.4.0.0 ../../lib/libopencv_imgcodecs.so.4.0.0 ../../lib/libopencv_imgproc.so.4.0.0 ../../lib/libopencv_core.so.4.0.0 ../../lib/libopencv_cudev.so.4.0.0
../../lib/libopencv_core.so.4.0.0: undefined reference to `cv::String::allocate(unsigned long)'
../../lib/libopencv_core.so.4.0.0: undefined reference to `cv::_OutputArray::create(cv::Size_<int>, int, int, bool, int) const'
../../lib/libopencv_core.so.4.0.0: undefined reference to `cv::error(int, cv::String const&, char const*, char const*, int)'
../../lib/libopencv_core.so.4.0.0: undefined reference to `cv::String::deallocate()'
collect2: error: ld returned 1 exit status
modules/phase_unwrapping/CMakeFiles/example_phase_unwrapping_unwrap.dir/build.make:90: recipe for target 'bin/example_phase_unwrapping_unwrap' failed
make[2]: *** [bin/example_phase_unwrapping_unwrap] Error 1
make[2]: Leaving directory '/home/khurram/LIBRARIES/OPENCV34/opencv/build'
CMakeFiles/Makefile2:3110: recipe for target 'modules/phase_unwrapping/CMakeFiles/example_phase_unwrapping_unwrap.dir/all' failed
make[1]: *** [modules/phase_unwrapping/CMakeFiles/example_phase_unwrapping_unwrap.dir/all] Error 2
make[1]: Leaving directory '/home/khurram/LIBRARIES/OPENCV34/opencv/build'
Makefile:162: recipe for target 'all' failed
make: *** [all] Error 2

System information (version)

OpenCV => 4.0.0-rc

Operating System / Platform => Linux GT72S 4.15.0-32-generic #35~16.04.1-Ubuntu SMP Fri Aug 10 21:54:34 UTC 2018 x86_64 x86_64 x86_64 GNU/Linux

Compiler =>

$ g++ -v
Using built-in specs.
COLLECT_GCC=g++
COLLECT_LTO_WRAPPER=/usr/lib/gcc/x86_64-linux-gnu/5/lto-wrapper
Target: x86_64-linux-gnu
Configured with: ../src/configure -v --with-pkgversion='Ubuntu 5.4.0-6ubuntu1~16.04.10' --with-bugurl=file:///usr/share/doc/gcc-5/README.Bugs --enable-languages=c,ada,c++,java,go,d,fortran,objc,obj-c++ --prefix=/usr --program-suffix=-5 --enable-shared --enable-linker-build-id --libexecdir=/usr/lib --without-included-gettext --enable-threads=posix --libdir=/usr/lib --enable-nls --with-sysroot=/ --enable-clocale=gnu --enable-libstdcxx-debug --enable-libstdcxx-time=yes --with-default-libstdcxx-abi=new --enable-gnu-unique-object --disable-vtable-verify --enable-libmpx --enable-plugin --with-system-zlib --disable-browser-plugin --enable-java-awt=gtk --enable-gtk-cairo --with-java-home=/usr/lib/jvm/java-1.5.0-gcj-5-amd64/jre --enable-java-home --with-jvm-root-dir=/usr/lib/jvm/java-1.5.0-gcj-5-amd64 --with-jvm-jar-dir=/usr/lib/jvm-exports/java-1.5.0-gcj-5-amd64 --with-arch-directory=amd64 --with-ecj-jar=/usr/share/java/eclipse-ecj.jar --enable-objc-gc --enable-multiarch --disable-werror --with-arch-32=i686 --with-abi=m64 --with-multilib-list=m32,m64,mx32 --enable-multilib --with-tune=generic --enable-checking=release --build=x86_64-linux-gnu --host=x86_64-linux-gnu --target=x86_64-linux-gnu
Thread model: posix
gcc version 5.4.0 20160609 (Ubuntu 5.4.0-6ubuntu1~16.04.10)

$ nvcc -V
nvcc: NVIDIA (R) Cuda compiler driver
Copyright (c) 2005-2017 NVIDIA Corporation
Built on Fri_Sep__1_21:08:03_CDT_2017
Cuda compilation tools, release 9.0, V9.0.176

CMAKE STDOUT

/home/khurram/miniconda3/bin/cmake -H/home/khurram/LIBRARIES/OPENCV34/opencv -B/home/khurram/LIBRARIES/OPENCV34/opencv/build --check-build-system CMakeFiles/Makefile.cmake 0
Re-run cmake file: Makefile older than: modules/cudaarithm/CMakeFiles/cuda_compile_1.dir/src/cuda/cuda_compile_1_generated_threshold.cu.o.depend
-- Looking for ccache - not found
-- Found ZLIB: /home/khurram/miniconda3/lib/libz.so.1.2.11 (found suitable version "1.2.11", minimum required is "1.2.3")
-- Found ZLIB: /home/khurram/miniconda3/lib/libz.so.1.2.11 (found version "1.2.11")
-- Found OpenEXR: /usr/lib/x86_64-linux-gnu/libIlmImf.so
-- Checking for module 'gtk+-3.0'
-- No package 'gtk+-3.0' found
-- Checking for module 'gstreamer-base-1.0'
-- No package 'gstreamer-base-1.0' found
-- Checking for module 'gstreamer-video-1.0'
-- No package 'gstreamer-video-1.0' found
-- Checking for module 'gstreamer-app-1.0'
-- No package 'gstreamer-app-1.0' found
-- Checking for module 'gstreamer-riff-1.0'
-- No package 'gstreamer-riff-1.0' found
-- Checking for module 'gstreamer-pbutils-1.0'
-- No package 'gstreamer-pbutils-1.0' found
-- Looking for linux/videodev2.h
-- Looking for linux/videodev2.h - found
-- Looking for sys/videoio.h
-- Looking for sys/videoio.h - not found
-- Checking for module 'libavresample'
-- No package 'libavresample' found
-- found Intel IPP (ICV version): 2019.0.0 [2019.0.0 Gold]
-- at: /home/khurram/LIBRARIES/OPENCV34/opencv/build/3rdparty/ippicv/ippicv_lnx/icv
-- found Intel IPP Integration Wrappers sources: 2019.0.0
-- at: /home/khurram/LIBRARIES/OPENCV34/opencv/build/3rdparty/ippicv/ippicv_lnx/iw
-- CUDA detected: 9.0
-- CUDA NVCC target flags: -gencode;arch=compute_30,code=sm_30;-gencode;arch=compute_35,code=sm_35;-gencode;arch=compute_37,code=sm_37;-gencode;arch=compute_50,code=sm_50;-gencode;arch=compute_52,code=sm_52;-gencode;arch=compute_60,code=sm_60;-gencode;arch=compute_61,code=sm_61;-gencode;arch=compute_70,code=sm_70;-D_FORCE_INLINES
-- LAPACK(MKL): LAPACK_LIBRARIES: /home/khurram/miniconda3/lib/libmkl_intel_lp64.so;/home/khurram/miniconda3/lib/libmkl_sequential.so;/home/khurram/miniconda3/lib/libmkl_core.so;/home/khurram/miniconda3/lib/libmkl_intel_lp64.so;/home/khurram/miniconda3/lib/libmkl_sequential.so;/home/khurram/miniconda3/lib/libmkl_core.so;/home/khurram/miniconda3/lib/libmkl_intel_lp64.so;/home/khurram/miniconda3/lib/libmkl_sequential.so;/home/khurram/miniconda3/lib/libmkl_core.so;-lpthread;-lm;-ldl
-- LAPACK(MKL): Support is enabled.
-- Could NOT find JNI (missing: JAVA_INCLUDE_PATH JAVA_INCLUDE_PATH2 JAVA_AWT_INCLUDE_PATH)
-- Could NOT find Pylint (missing: PYLINT_EXECUTABLE)
-- Could NOT find Flake8 (missing: FLAKE8_EXECUTABLE)
-- VTK is not found. Please set -DVTK_DIR in CMake to VTK build directory, or to VTK install subdirectory with VTKConfig.cmake file
-- Caffe: NO
CMake Warning at /home/khurram/miniconda3/share/cmake-3.12/Modules/FindProtobuf.cmake:455 (message):
Protobuf compiler version 3.6.0 doesn't match library version 3.6.1
Call Stack (most recent call first):
/home/khurram/LIBRARIES/OPENCV34/opencv_contrib/modules/cnn_3dobj/CMakeLists.txt:14 (find_package)

-- Protobuf: YES
-- Glog: YES
-- freetype2: YES
-- harfbuzz: YES
-- HDF5: Using hdf5 compiler wrapper to determine C configuration
-- Module opencv_ovis disabled because OGRE3D was not found
-- No preference for use of exported gflags CMake configuration set, and no hints for include/library directories provided. Defaulting to preferring an installed/exported gflags CMake configuration if available.
-- Failed to find installed gflags CMake configuration, searching for gflags build directories exported with CMake.
-- Failed to find gflags - Failed to find an installed/exported CMake configuration for gflags, will perform search for installed gflags components.
-- Checking SFM deps... TRUE
-- CERES support is disabled. Ceres Solver for reconstruction API is required.
-- Module opencv_dnn_objdetect disabled because opencv_dnn dependency can't be resolved!
-- Module opencv_text disabled because opencv_dnn dependency can't be resolved!
-- freetype2: YES
-- harfbuzz: YES
-- No preference for use of exported gflags CMake configuration set, and no hints for include/library directories provided. Defaulting to preferring an installed/exported gflags CMake configuration if available.
-- Failed to find installed gflags CMake configuration, searching for gflags build directories exported with CMake.
-- Failed to find gflags - Failed to find an installed/exported CMake configuration for gflags, will perform search for installed gflags components.
-- Checking SFM deps... TRUE
-- CERES support is disabled. Ceres Solver for reconstruction API is required.
-- OpenCL samples are skipped: OpenCL SDK is required
--
-- General configuration for OpenCV 4.0.0-rc =====================================
-- Version control: 4.0.0-rc
--
-- Extra modules:
-- Location (extra): /home/khurram/LIBRARIES/OPENCV34/opencv_contrib/modules
-- Version control (extra): 4.0.0-rc
--
-- Platform:
-- Timestamp: 2018-11-16T15:59:03Z
-- Host: Linux 4.15.0-32-generic x86_64
-- CMake: 3.12.2
-- CMake generator: Unix Makefiles
-- CMake build tool: /usr/bin/make
-- Configuration: RELEASE
--
-- CPU/HW features:
-- Baseline: SSE SSE2 SSE3
-- requested: SSE3
-- Dispatched code generation: SSE4_1 SSE4_2 FP16 AVX AVX2 AVX512_SKX
-- requested: SSE4_1 SSE4_2 AVX FP16 AVX2 AVX512_SKX
-- SSE4_1 (4 files): + SSSE3 SSE4_1
-- SSE4_2 (1 files): + SSSE3 SSE4_1 POPCNT SSE4_2
-- FP16 (0 files): + SSSE3 SSE4_1 POPCNT SSE4_2 FP16 AVX
-- AVX (3 files): + SSSE3 SSE4_1 POPCNT SSE4_2 AVX
-- AVX2 (9 files): + SSSE3 SSE4_1 POPCNT SSE4_2 FP16 FMA3 AVX AVX2
-- AVX512_SKX (0 files): + SSSE3 SSE4_1 POPCNT SSE4_2 FP16 FMA3 AVX AVX2 AVX_512F AVX512_SKX
--
-- C/C++:
-- Built as dynamic libs?: YES
-- C++ Compiler: /usr/bin/c++ (ver 5.4.0)
-- C++ flags (Release): -g -H -fsigned-char -W -Wall -Werror=return-type -Werror=non-virtual-dtor -Werror=address -Werror=sequence-point -Wformat -Werror=format-security -Wmissing-declarations -Wundef -Winit-self -Wpointer-arith -Wshadow -Wsign-promo -Wuninitialized -Winit-self -Wno-narrowing -Wno-delete-non-virtual-dtor -Wno-comment -fdiagnostics-show-option -Wno-long-long -pthread -fomit-frame-pointer -ffunction-sections -fdata-sections -msse -msse2 -msse3 -fvisibility=hidden -fvisibility-inlines-hidden -O3 -DNDEBUG -DNDEBUG
-- C++ flags (Debug): -g -H -fsigned-char -W -Wall -Werror=return-type -Werror=non-virtual-dtor -Werror=address -Werror=sequence-point -Wformat -Werror=format-security -Wmissing-declarations -Wundef -Winit-self -Wpointer-arith -Wshadow -Wsign-promo -Wuninitialized -Winit-self -Wno-narrowing -Wno-delete-non-virtual-dtor -Wno-comment -fdiagnostics-show-option -Wno-long-long -pthread -fomit-frame-pointer -ffunction-sections -fdata-sections -msse -msse2 -msse3 -fvisibility=hidden -fvisibility-inlines-hidden -g -O0 -DDEBUG -D_DEBUG
-- C Compiler: /usr/bin/cc
-- C flags (Release): -fsigned-char -W -Wall -Werror=return-type -Werror=non-virtual-dtor -Werror=address -Werror=sequence-point -Wformat -Werror=format-security -Wmissing-declarations -Wmissing-prototypes -Wstrict-prototypes -Wundef -Winit-self -Wpointer-arith -Wshadow -Wuninitialized -Winit-self -Wno-narrowing -Wno-comment -fdiagnostics-show-option -Wno-long-long -pthread -fomit-frame-pointer -ffunction-sections -fdata-sections -msse -msse2 -msse3 -fvisibility=hidden -O3 -DNDEBUG -DNDEBUG
-- C flags (Debug): -fsigned-char -W -Wall -Werror=return-type -Werror=non-virtual-dtor -Werror=address -Werror=sequence-point -Wformat -Werror=format-security -Wmissing-declarations -Wmissing-prototypes -Wstrict-prototypes -Wundef -Winit-self -Wpointer-arith -Wshadow -Wuninitialized -Winit-self -Wno-narrowing -Wno-comment -fdiagnostics-show-option -Wno-long-long -pthread -fomit-frame-pointer -ffunction-sections -fdata-sections -msse -msse2 -msse3 -fvisibility=hidden -g -O0 -DDEBUG -D_DEBUG
-- Linker flags (Release):
-- Linker flags (Debug):
-- ccache: NO
-- Precompiled headers: YES
-- Extra dependencies: m pthread cudart_static -lpthread dl rt nppc nppial nppicc nppicom nppidei nppif nppig nppim nppist nppisu nppitc npps cublas cufft -L/usr/local/cuda-9.0/lib64 -L/usr/lib/x86_64-linux-gnu
-- 3rdparty dependencies:
--
-- OpenCV modules:
-- To be built: aruco bgsegm bioinspired calib3d ccalib core cudaarithm cudabgsegm cudacodec cudafeatures2d cudafilters cudaimgproc cudalegacy cudaobjdetect cudaoptflow cudastereo cudawarping cudev datasets dpm face features2d flann freetype fuzzy gapi hfs highgui img_hash imgcodecs imgproc java_bindings_generator line_descriptor ml objdetect optflow phase_unwrapping photo plot python3 python_bindings_generator reg rgbd saliency sfm shape stereo stitching structured_light superres surface_matching tracking video videoio videostab xfeatures2d ximgproc xobjdetect xphoto
-- Disabled: hdf python2 world
-- Disabled by dependency: dnn_objdetect text
-- Unavailable: cnn_3dobj cvv dnn java js matlab ovis ts viz
-- Applications: examples apps
-- Documentation: NO
-- Non-free algorithms: YES
--
-- GUI:
-- GTK+: YES (ver 2.24.30)
-- GThread : YES (ver 2.48.2)
-- GtkGlExt: NO
-- VTK support: NO
--
-- Media I/O:
-- ZLib: /home/khurram/miniconda3/lib/libz.so.1.2.11 (ver 1.2.11)
-- JPEG: /usr/lib/x86_64-linux-gnu/libjpeg.so (ver 80)
-- WEBP: /usr/lib/x86_64-linux-gnu/libwebp.so (ver encoder: 0x0202)
-- PNG: /usr/lib/x86_64-linux-gnu/libpng.so (ver 1.2.54)
-- TIFF: /home/khurram/miniconda3/lib/libtiff.so (ver 42 / 4.0.9)
-- JPEG 2000: /usr/lib/x86_64-linux-gnu/libjasper.so (ver 1.900.1)
-- OpenEXR: /usr/lib/x86_64-linux-gnu/libImath.so /usr/lib/x86_64-linux-gnu/libIlmImf.so /usr/lib/x86_64-linux-gnu/libIex.so /usr/lib/x86_64-linux-gnu/libHalf.so /usr/lib/x86_64-linux-gnu/libIlmThread.so (ver 2.2.0)
-- HDR: YES
-- SUNRASTER: YES
-- PXM: YES
-- PFM: YES
--
-- Video I/O:
-- DC1394: YES (ver 2.2.4)
-- FFMPEG: YES
-- avcodec: YES (ver 58.19.100)
-- avformat: YES (ver 58.13.100)
-- avutil: YES (ver 56.15.100)
-- swscale: YES (ver 5.2.100)
-- avresample: NO
-- GStreamer:
-- base: YES (ver 0.10.36)
-- video: YES (ver 0.10.36)
-- app: YES (ver 0.10.36)
-- riff: YES (ver 0.10.36)
-- pbutils: YES (ver 0.10.36)
-- v4l/v4l2: linux/videodev2.h
--
-- Parallel framework: pthreads
--
-- Trace: YES (with Intel ITT)
--
-- Other third-party libraries:
-- Intel IPP: 2019.0.0 Gold [2019.0.0]
-- at: /home/khurram/LIBRARIES/OPENCV34/opencv/build/3rdparty/ippicv/ippicv_lnx/icv
-- Intel IPP IW: sources (2019.0.0)
-- at: /home/khurram/LIBRARIES/OPENCV34/opencv/build/3rdparty/ippicv/ippicv_lnx/iw
-- Lapack: YES (/home/khurram/miniconda3/lib/libmkl_intel_lp64.so /home/khurram/miniconda3/lib/libmkl_sequential.so /home/khurram/miniconda3/lib/libmkl_core.so /home/khurram/miniconda3/lib/libmkl_intel_lp64.so /home/khurram/miniconda3/lib/libmkl_sequential.so /home/khurram/miniconda3/lib/libmkl_core.so /home/khurram/miniconda3/lib/libmkl_intel_lp64.so /home/khurram/miniconda3/lib/libmkl_sequential.so /home/khurram/miniconda3/lib/libmkl_core.so -lpthread -lm -ldl)
-- Eigen: YES (ver 3.3.90)
-- Custom HAL: NO
--
-- NVIDIA CUDA: YES (ver 9.0, CUFFT CUBLAS NVCUVID)
-- NVIDIA GPU arch: 30 35 37 50 52 60 61 70
-- NVIDIA PTX archs:
--
-- OpenCL: YES (no extra features)
-- Include path: /home/khurram/LIBRARIES/OPENCV34/opencv/3rdparty/include/opencl/1.2
-- Link libraries: Dynamic load
--
-- Python 3:
-- Interpreter: /home/khurram/miniconda3/bin/python3.5m (ver 3.5.6)
-- Libraries: /home/khurram/miniconda3/lib/libpython3.5m.so (ver 3.5.6)
-- numpy: /home/khurram/miniconda3/lib/python3.5/site-packages/numpy/core/include (ver 1.15.2)
-- packages path: /home/khurram/miniconda3/lib/python3.5/site-packages
--
-- Python (for build): /usr/bin/python2.7
--
-- Java:
-- ant: NO
-- JNI: NO
-- Java wrappers: NO
-- Java tests: NO
--
-- Install to: /home/khurram/miniconda3
-- -----------------------------------------------------------------
--
-- Configuring done
-- Generating done
-- Build files have been written to: /home/khurram/LIBRARIES/OPENCV34/opencv/build

Detailed description

System information (version)

OpenCV => ❔

Operating System / Platform => ❔

Compiler => ❔

Detailed description

Steps to reproduce

Issue 2:
System information (version)

OpenCV =>3.4.3

Operating System / Platform => Ubuntu14.04

Compiler =>cmake

Detailed description

My project runs normal which contains other OpenCV module until I attach parts of code about dnn to load a YOLO model for object detection。

I use CMakeList.txt to generate Makefile which build the program.I can generate the executable file and .so file and they run fine.But when I want to delete source file and generate executable file by .so file,it goes wrong.What shoud I do to CMakeList.txt to solve the problem.

Steps to reproduce

**CMakeList.txt(exe&.so)**

cmake_minimum_required(VERSION 3.5)
project(algorithm-sdk)

set(CMAKE_CXX_STANDARD 11)
find_package(OpenCV REQUIRED)

add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/3rd/cJSON)
add_library(SmokeDetectAlgorithm SHARED ${CMAKE_CURRENT_SOURCE_DIR}/src/SmokeDetectAlgorithm.cpp)

include_directories(${CMAKE_CURRENT_SOURCE_DIR}/include)
target_link_libraries(SmokeDetectAlgorithm
cjson
)

add_executable(test-algo-sdk
${CMAKE_CURRENT_SOURCE_DIR}/src/main.cpp
${CMAKE_CURRENT_SOURCE_DIR}/src/SmokeDetectAlgorithm.cpp
)

target_include_directories(test-algo-sdk
PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/include
PUBLIC ${OpenCV_INCLUDE_DIRS})

target_link_libraries(test-algo-sdk
${OpenCV_LIBS}
cjson
m
#	${CMAKE_CURRENT_SOURCE_DIR}/build/libSmokeDetectAlgorithm.so
dl
)

CMakeList.txt(.so only)

cmake_minimum_required(VERSION 3.5)
project(algorithm-sdk)

set(CMAKE_CXX_STANDARD 11)
find_package(OpenCV REQUIRED)

add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/3rd/cJSON)
#add_library(SmokeDetectAlgorithm SHARED ${CMAKE_CURRENT_SOURCE_DIR}/src/SmokeDetectAlgorithm.cpp)

include_directories(${CMAKE_CURRENT_SOURCE_DIR}/include)
target_link_libraries(#SmokeDetectAlgorithm
cjson
)

add_executable(test-algo-sdk
${CMAKE_CURRENT_SOURCE_DIR}/src/main.cpp
#	${CMAKE_CURRENT_SOURCE_DIR}/src/SmokeDetectAlgorithm.cpp
)

target_include_directories(test-algo-sdk
PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/include
PUBLIC ${OpenCV_INCLUDE_DIRS})

target_link_libraries(test-algo-sdk
${OpenCV_LIBS}
cjson
m
${CMAKE_CURRENT_SOURCE_DIR}/build/libSmokeDetectAlgorithm.so
dl
)