Issue 1:
System information (version)

OpenCV => 4.0.0 beta

Operating System / Platform => Windows 7 64 Bit

Compiler => Visual Studio 2015 build tool , cmake, nmake

Detailed description

the code in modules\stitching\src\blenders.cpp

#ifdef HAVE_CUDA
namespace cv { namespace cuda { namespace device {
namespace blend
{
void addSrcWeightGpu16S(const PtrStep<short> src, const PtrStep<short> src_weight,
PtrStep<short> dst, PtrStep<short> dst_weight, cv::Rect &rc);
void addSrcWeightGpu32F(const PtrStep<short> src, const PtrStepf src_weight,
PtrStep<short> dst, PtrStepf dst_weight, cv::Rect &rc);
void normalizeUsingWeightMapGpu16S(const PtrStep<short> weight, PtrStep<short> src,
const int width, const int height);
void normalizeUsingWeightMapGpu32F(const PtrStepf weight, PtrStep<short> src,
const int width, const int height);
}
}
}
}
#endif

arose an error c3083,

'device': the symbol to the left of a '::' must be a type

'blend': is not a member of 'cv::cuda'

guess the #ifdef was broken, HAVE_CUDA was ineffective, but in other cuda related modules no error occured

seems the compiler prefers the "\contrib\modules\cudafeatures2d\include\opencv2\cudafeatures2d.hpp" to be the definition; while "modules\stitching\src\cuda\multiband_blend.cu" was the definition of functions

the cmake.txt was simple, i did not notice anything related to the cu file

what should i do now?

Steps to reproduce

using cmake-gui and nmake , simply chechk the cuda stuffs and extra packages

wait until 93% was done, and enounter the error

the screen was like:

Scanning dependencies of target opencv_stitching
[ 93%] Building CXX object modules/stitching/CMakeFiles/opencv_stitching.dir/src/blenders.cpp.obj
blenders.cpp
D:\download\opencv4\modules\stitching\src\blenders.cpp(473): error C3083: 'device': the symbol to the left of a '::' must be a type
D:\download\opencv4\modules\stitching\src\blenders.cpp(473): error C2039: 'blend': is not a member of 'cv::cuda'
D:\download\opencv4\contrib\modules\cudafeatures2d\include\opencv2/cudafeatures2d.hpp(61): note: see declaration of 'cv::cuda'
D:\download\opencv4\modules\stitching\src\blenders.cpp(473): error C2871: 'blend': a namespace with this name does not exist
D:\download\opencv4\modules\stitching\src\blenders.cpp(476): error C3861: 'addSrcWeightGpu32F': identifier not found
D:\download\opencv4\modules\stitching\src\blenders.cpp(480): error C3861: 'addSrcWeightGpu16S': identifier not found
D:\download\opencv4\modules\stitching\src\blenders.cpp(620): error C3083: 'device': the symbol to the left of a '::' must be a type
D:\download\opencv4\modules\stitching\src\blenders.cpp(620): error C2039: 'blend': is not a member of 'cv::cuda'
D:\download\opencv4\contrib\modules\cudafeatures2d\include\opencv2/cudafeatures2d.hpp(61): note: see declaration of 'cv::cuda'
D:\download\opencv4\modules\stitching\src\blenders.cpp(620): error C2871: 'blend': a namespace with this name does not exist
D:\download\opencv4\modules\stitching\src\blenders.cpp(623): error C3861: 'normalizeUsingWeightMapGpu32F': identifier not found
D:\download\opencv4\modules\stitching\src\blenders.cpp(627): error C3861: 'normalizeUsingWeightMapGpu16S': identifier not found
NMAKE : fatal error U1077: 'C:\PROGRA~2\MICROS~1.0\VC\bin\amd64\cl.exe' : return code '0x2'
Stop.
NMAKE : fatal error U1077: '"C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\BIN\amd64\nmake.exe"' : return code '0x2'
Stop.
NMAKE : fatal error U1077: '"C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\BIN\amd64\nmake.exe"' : return code '0x2'
Stop.

further if i remove the preprocesser token, and hard code the namespaces and the functions ,

//#ifdef HAVE_CUDA

namespace cv { namespace cuda { namespace device {
namespace blend
{
void addSrcWeightGpu16S(const PtrStep<short> src, const PtrStep<short> src_weight,
PtrStep<short> dst, PtrStep<short> dst_weight, cv::Rect &rc);
void addSrcWeightGpu32F(const PtrStep<short> src, const PtrStepf src_weight,
PtrStep<short> dst, PtrStepf dst_weight, cv::Rect &rc);
void normalizeUsingWeightMapGpu16S(const PtrStep<short> weight, PtrStep<short> src,
const int width, const int height);
void normalizeUsingWeightMapGpu32F(const PtrStepf weight, PtrStep<short> src,
const int width, const int height);
}
}
}
}
//#endif

it will compile this file, but link will throw an error like this:

#13019 (comment)

the screen was like:

Scanning dependencies of target opencv_stitching
[ 93%] Building CXX object modules/stitching/CMakeFiles/opencv_stitching.dir/src/blenders.cpp.obj
blenders.cpp
[ 93%] Building CXX object modules/stitching/CMakeFiles/opencv_stitching.dir/src/camera.cpp.obj
camera.cpp
[ 93%] Building CXX object modules/stitching/CMakeFiles/opencv_stitching.dir/src/exposure_compensate.cpp.obj
exposure_compensate.cpp
[ 93%] Building CXX object modules/stitching/CMakeFiles/opencv_stitching.dir/src/matchers.cpp.obj
matchers.cpp
[ 93%] Building CXX object modules/stitching/CMakeFiles/opencv_stitching.dir/src/motion_estimators.cpp.obj
motion_estimators.cpp
[ 93%] Building CXX object modules/stitching/CMakeFiles/opencv_stitching.dir/src/seam_finders.cpp.obj
seam_finders.cpp
[ 93%] Building CXX object modules/stitching/CMakeFiles/opencv_stitching.dir/src/stitcher.cpp.obj
stitcher.cpp
[ 93%] Building CXX object modules/stitching/CMakeFiles/opencv_stitching.dir/src/timelapsers.cpp.obj
timelapsers.cpp
[ 93%] Building CXX object modules/stitching/CMakeFiles/opencv_stitching.dir/src/util.cpp.obj
util.cpp
[ 93%] Building CXX object modules/stitching/CMakeFiles/opencv_stitching.dir/src/warpers.cpp.obj
warpers.cpp
[ 94%] Building CXX object modules/stitching/CMakeFiles/opencv_stitching.dir/src/warpers_cuda.cpp.obj
warpers_cuda.cpp
d:\download\opencv4\modules\stitching\include\opencv2\stitching\detail\warpers.hpp(451) : warning C4702: unreachable code
d:\download\opencv4\modules\stitching\src\warpers_cuda.cpp(202) : warning C4702: unreachable code
d:\download\opencv4\modules\stitching\src\warpers_cuda.cpp(203) : warning C4702: unreachable code
d:\download\opencv4\modules\stitching\src\warpers_cuda.cpp(204) : warning C4702: unreachable code
d:\download\opencv4\modules\stitching\include\opencv2\stitching\detail\warpers.hpp(497) : warning C4702: unreachable code
d:\download\opencv4\modules\stitching\src\warpers_cuda.cpp(244) : warning C4702: unreachable code
d:\download\opencv4\modules\stitching\src\warpers_cuda.cpp(245) : warning C4702: unreachable code
d:\download\opencv4\modules\stitching\src\warpers_cuda.cpp(288) : warning C4702: unreachable code
d:\download\opencv4\modules\stitching\src\warpers_cuda.cpp(246) : warning C4702: unreachable code
d:\download\opencv4\modules\stitching\include\opencv2\stitching\detail\warpers.hpp(529) : warning C4702: unreachable code
d:\download\opencv4\modules\stitching\src\warpers_cuda.cpp(289) : warning C4702: unreachable code
d:\download\opencv4\modules\stitching\src\warpers_cuda.cpp(290) : warning C4702: unreachable code
d:\download\opencv4\modules\stitching\include\opencv2\stitching\detail\warpers.hpp(443) : warning C4702: unreachable code
d:\download\opencv4\modules\stitching\include\opencv2\stitching\detail\warpers.hpp(470) : warning C4702: unreachable code
d:\download\opencv4\modules\stitching\include\opencv2\stitching\detail\warpers.hpp(539) : warning C4702: unreachable code
d:\download\opencv4\modules\stitching\include\opencv2\stitching\detail\warpers.hpp(507) : warning C4702: unreachable code
d:\download\opencv4\modules\stitching\include\opencv2\stitching\detail\warpers.hpp(461) : warning C4702: unreachable code
[ 94%] Building CXX object modules/stitching/CMakeFiles/opencv_stitching.dir/opencl_kernels_stitching.cpp.obj
opencl_kernels_stitching.cpp
[ 94%] Building RC object modules/stitching/CMakeFiles/opencv_stitching.dir/vs_version.rc.res
Microsoft (R) Windows (R) Resource Compiler Version 6.3.9600.17336
Copyright (C) Microsoft Corporation. All rights reserved.

[ 94%] Building CXX object modules/stitching/CMakeFiles/opencv_stitching.dir/opencv_stitching_main.cpp.obj
opencv_stitching_main.cpp
[ 94%] Linking CXX shared library ..\..\bin\opencv_stitching400.dll
Creating library ..\..\lib\opencv_stitching400.lib and object ..\..\lib\opencv_stitching400.exp
blenders.cpp.obj : error LNK2019: unresolved external symbol "void __cdecl cv::cuda::device::blend::addSrcWeightGpu16S(struct cv::cuda::PtrStep<s
hort>,struct cv::cuda::PtrStep<short>,struct cv::cuda::PtrStep<short>,struct cv::cuda::PtrStep<short>,class cv::Rect_<int> &)" (?addSrcWeightGpu1
6S@blend@device@cuda@cv@@YAXU?$PtrStep@F@34@0U534@1AEAV?$Rect_@H@4@@Z) referenced in function "public: virtual void __cdecl cv::detail::MultiBand
Blender::feed(class cv::_InputArray const &,class cv::_InputArray const &,class cv::Point_<int>)" (?feed@MultiBandBlender@detail@cv@@UEAAXAEBV_In
putArray@3@0V?$Point_@H@3@@Z)
blenders.cpp.obj : error LNK2019: unresolved external symbol "void __cdecl cv::cuda::device::blend::addSrcWeightGpu32F(struct cv::cuda::PtrStep<s
hort>,struct cv::cuda::PtrStep<float>,struct cv::cuda::PtrStep<short>,struct cv::cuda::PtrStep<float>,class cv::Rect_<int> &)" (?addSrcWeightGpu3
2F@blend@device@cuda@cv@@YAXU?$PtrStep@F@34@U?$PtrStep@M@34@U534@U634@AEAV?$Rect_@H@4@@Z) referenced in function "public: virtual void __cdecl cv
::detail::MultiBandBlender::feed(class cv::_InputArray const &,class cv::_InputArray const &,class cv::Point_<int>)" (?feed@MultiBandBlender@deta
il@cv@@UEAAXAEBV_InputArray@3@0V?$Point_@H@3@@Z)
blenders.cpp.obj : error LNK2019: unresolved external symbol "void __cdecl cv::cuda::device::blend::normalizeUsingWeightMapGpu16S(struct cv::cuda
::PtrStep<short>,struct cv::cuda::PtrStep<short>,int,int)" (?normalizeUsingWeightMapGpu16S@blend@device@cuda@cv@@YAXU?$PtrStep@F@34@U534@HH@Z) re
ferenced in function "public: virtual void __cdecl cv::detail::MultiBandBlender::blend(class cv::_InputOutputArray const &,class cv::_InputOutput
Array const &)" (?blend@MultiBandBlender@detail@cv@@UEAAXAEBV_InputOutputArray@3@0@Z)
blenders.cpp.obj : error LNK2019: unresolved external symbol "void __cdecl cv::cuda::device::blend::normalizeUsingWeightMapGpu32F(struct cv::cuda
::PtrStep<float>,struct cv::cuda::PtrStep<short>,int,int)" (?normalizeUsingWeightMapGpu32F@blend@device@cuda@cv@@YAXU?$PtrStep@M@34@U?$PtrStep@F@
34@HH@Z) referenced in function "public: virtual void __cdecl cv::detail::MultiBandBlender::blend(class cv::_InputOutputArray const &,class cv::_
InputOutputArray const &)" (?blend@MultiBandBlender@detail@cv@@UEAAXAEBV_InputOutputArray@3@0@Z)
..\..\bin\opencv_stitching400.dll : fatal error LNK1120: 4 unresolved externals
LINK failed. with 1120
NMAKE : fatal error U1077: '"C:\Program Files\cmake\bin\cmake.exe"' : return code '0xffffffff'
Stop.
NMAKE : fatal error U1077: '"C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\BIN\amd64\nmake.exe"' : return code '0x2'
Stop.
NMAKE : fatal error U1077: '"C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\BIN\amd64\nmake.exe"' : return code '0x2'
Stop.

finally it come to the question,

how to make sure of HAVE_CUDA

and

why unresolved external symbol in the same file when the compiled code should be there

Issue 2:
System information (version)

OpenCV => 4.0.0 beta

Operating System / Platform => Windows 7 64 Bit

Compiler => Visual Studio 2015 build tool with cmake and nmake

Detailed description

compilation fails

the earliest fail i've forgot the scene,

it was in file "modules\cudaoptflow\src\farneback.cpp"

in line 48 ,the FarnebackOpticalFlow was reported by compiler to be ambiguous

i removed these code since the code was in #if !defined HAVE_CUDA || defined(CUDA_DISABLER) and i will use cuda

in file "modules\stitching\src\blenders.cpp"

in line 40 or somewhere the namespace cv::cuda::device::blend don't exist. Obviously the #ifdef HAVE_CUDA did not work.

i modified it by removing the #ifdef , expose the code to the outer, for the same reason since i will use cuda

it worked

problem continues and maybe worse:

[ 88%] Linking CXX executable ..\..\bin\opencv_perf_cudaoptflow.exe

perf_optflow.cpp.obj : error LNK2019: unresolved external symbol

"public: static struct cv::Ptr<class cv::cuda::FarnebackOpticalFlow> __cdecl cv::cuda::FarnebackOpticalFlow::create(int,double,bool,int,int,int,double,int)"

(?create@FarnebackOpticalFlow@cuda@cv@@SA?AU?$Ptr@VFarnebackOpticalFlow@cuda@cv@@@3@HN_NHHHNH@Z)

referenced in function

"protected: virtual void __cdecl
opencv_test::`anonymous namespace'::ImagePair_FarnebackOpticalFlow::PerfTestBody(void)" (?PerfTestBody@ImagePair_FarnebackOpticalFlow@?A0x63873ea8@opencv_test@@MEAAXXZ)

..\..\bin\opencv_perf_cudaoptflow.exe : fatal error LNK1120: 1 unresolved externals
LINK failed. with 1120
NMAKE : fatal error U1077: '"C:\Program Files\cmake\bin\cmake.exe"' : return code '0xffffffff'
Stop.
NMAKE : fatal error U1077: '"C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\BIN\amd64\nmake.exe"' : return code '0x2'

Stop.
NMAKE : fatal error U1077: '"C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\BIN\amd64\nmake.exe"' : return code '0x2'

Stop.

i re-run cmake, unchecked perf-test, and rerun nmake

the perf_cudaoptflow.exe was "avoided", but bug was not fixed, i got this soon:

----------------------------------------------------------------------------------
[ 94%] Linking CXX shared library ..\..\bin\opencv_stitching400.dll
Creating library ..\..\lib\opencv_stitching400.lib and object ..\..\lib\opencv_stitching400.exp
blenders.cpp.obj : error LNK2019: unresolved external symbol "void __cdecl cv::cuda::device::blend::addSrcWeightGpu16S(struct
cv::cuda::PtrStep<short>,struct cv::cuda::PtrStep<short>,struct cv::cuda::PtrStep<short>,struct cv::cuda::PtrStep<short>,cla
ss cv::Rect_<int> &)" (?addSrcWeightGpu16S@blend@device@cuda@cv@@YAXU?$PtrStep@F@34@0U534@1AEAV?$Rect_@H@4@@Z) referenced in
function "public: virtual void __cdecl cv::detail::MultiBandBlender::feed(class cv::_InputArray const &,class cv::_InputArray
const &,class cv::Point_<int>)" (?feed@MultiBandBlender@detail@cv@@UEAAXAEBV_InputArray@3@0V?$Point_@H@3@@Z)
blenders.cpp.obj : error LNK2019: unresolved external symbol "void __cdecl cv::cuda::device::blend::addSrcWeightGpu32F(struct
cv::cuda::PtrStep<short>,struct cv::cuda::PtrStep<float>,struct cv::cuda::PtrStep<short>,struct cv::cuda::PtrStep<float>,cla
ss cv::Rect_<int> &)" (?addSrcWeightGpu32F@blend@device@cuda@cv@@YAXU?$PtrStep@F@34@U?$PtrStep@M@34@U534@U634@AEAV?$Rect_@H@4
@@Z) referenced in function "public: virtual void __cdecl cv::detail::MultiBandBlender::feed(class cv::_InputArray const &,cl
ass cv::_InputArray const &,class cv::Point_<int>)" (?feed@MultiBandBlender@detail@cv@@UEAAXAEBV_InputArray@3@0V?$Point_@H@3@
@Z)
blenders.cpp.obj : error LNK2019: unresolved external symbol "void __cdecl cv::cuda::device::blend::normalizeUsingWeightMapGp
u16S(struct cv::cuda::PtrStep<short>,struct cv::cuda::PtrStep<short>,int,int)" (?normalizeUsingWeightMapGpu16S@blend@device@c
uda@cv@@YAXU?$PtrStep@F@34@U534@HH@Z) referenced in function "public: virtual void __cdecl cv::detail::MultiBandBlender::blen
d(class cv::_InputOutputArray const &,class cv::_InputOutputArray const &)" (?blend@MultiBandBlender@detail@cv@@UEAAXAEBV_Inp
utOutputArray@3@0@Z)
blenders.cpp.obj : error LNK2019: unresolved external symbol "void __cdecl cv::cuda::device::blend::normalizeUsingWeightMapGp
u32F(struct cv::cuda::PtrStep<float>,struct cv::cuda::PtrStep<short>,int,int)" (?normalizeUsingWeightMapGpu32F@blend@device@c
uda@cv@@YAXU?$PtrStep@M@34@U?$PtrStep@F@34@HH@Z) referenced in function "public: virtual void __cdecl cv::detail::MultiBandBl
ender::blend(class cv::_InputOutputArray const &,class cv::_InputOutputArray const &)" (?blend@MultiBandBlender@detail@cv@@UE
AAXAEBV_InputOutputArray@3@0@Z)
..\..\bin\opencv_stitching400.dll : fatal error LNK1120: 4 unresolved externals
LINK failed. with 1120
NMAKE : fatal error U1077: '"C:\Program Files\cmake\bin\cmake.exe"' : return code '0xffffffff'
Stop.
NMAKE : fatal error U1077: '"C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\BIN\amd64\nmake.exe"' : return code '0x2'

Stop.
NMAKE : fatal error U1077: '"C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\BIN\amd64\nmake.exe"' : return code '0x2'

Stop.

i did not dive into code yet, was this encountered yet or was it only my fault???

Steps to reproduce

the real problem was "unresolved external symbol"