opencv / opencv_contrib

Repository for OpenCV's extra modules
Apache License 2.0
9.36k stars 5.75k forks source link

j0 , j1, jn was not declared in this scope, edit math.h will fix, but please …… #3013

Closed garfeng closed 3 years ago

garfeng commented 3 years ago
System information (version)
Detailed description
[ 90%] Building CXX object modules/sfm/src/libmv/libmv/multiview/CMakeFiles/multiview.dir/fundamental.cc.obj
In file included from F:/msys64/mingw64/include/ceres/internal/autodiff.h:153,
                 from F:/msys64/mingw64/include/ceres/autodiff_cost_function.h:130,
                 from F:/msys64/mingw64/include/ceres/ceres.h:37,
                 from F:/opencv/opencv_contrib-4.5.3/modules/sfm/src/libmv_light/libmv/multiview/fundamental.cc:24:
F:/msys64/mingw64/include/ceres/jet.h: In function 'double ceres::BesselJ0(double)':
F:/msys64/mingw64/include/ceres/jet.h:603:10: error: 'j0' was not declared in this scope; did you mean 'V0'?
  603 |   return j0(x);
      |          ^~
      |          V0
F:/msys64/mingw64/include/ceres/jet.h: In function 'double ceres::BesselJ1(double)':
F:/msys64/mingw64/include/ceres/jet.h:610:10: error: 'j1' was not declared in this scope; did you mean 'V1'?
  610 |   return j1(x);
      |          ^~
      |          V1
F:/msys64/mingw64/include/ceres/jet.h: In function 'double ceres::BesselJn(int, double)':
F:/msys64/mingw64/include/ceres/jet.h:617:10: error: 'jn' was not declared in this scope; did you mean 'n'?
  617 |   return jn(n, x);
      |          ^~
      |          n
make[2]: *** [modules/sfm/src/libmv/libmv/multiview/CMakeFiles/multiview.dir/build.make:107:modules/sfm/src/libmv/libmv/multiview/CMakeFiles/multiview.dir/fundamental.cc.obj] 错误 1
make[1]: *** [CMakeFiles/Makefile2:5281:modules/sfm/src/libmv/libmv/multiview/CMakeFiles/multiview.dir/all] 错误 2
Steps to reproduce

cmake /f/opencv/opencv-4.5.3 -G "Unix Makefiles" -B/f/opencv/build_x64 -DENABLE_CXX11=ON -DOPENCV_EXTRA_MODULES_PATH=/f/opencv/opencv_contrib-4.5.3/modules -DBUILD_SHARED_LIBS=ON -DWITH_IPP=OFF -DWITH_MSMF=OFF -DBUILD_EXAMPLES=OFF -DBUILD_TESTS=OFF -DBUILD_PERF_TESTS=OFF -DBUILD_opencv_java=OFF -DBUILD_opencv_python=OFF -DBUILD_opencv_python2=OFF -DBUILD_opencv_python3=OFF -DBUILD_DOCS=OFF -DENABLE_PRECOMPILED_HEADERS=OFF -DBUILD_opencv_saliency=OFF -DBUILD_opencv_wechat_qrcode=OFF -DCPU_DISPATCH= -DOPENCV_GENERATE_PKGCONFIG=ON -DWITH_OPENCL_D3D11_NV=OFF -DOPENCV_ALLOCATOR_STATS_COUNTER_TYPE=int64_t -U__STRICT_ANSI__ -Wno-dev

cd /f/opencv/build_x64
make

I edit the F:\msys64\mingw64\x86_64-w64-mingw32\include\math.h by adding #undef __STRICT_ANSI__ to the top of the file, then the error disappears.

// math.h

#ifndef _MATH_H_
#define _MATH_H_

#undef __STRICT_ANSI__  // <= I add this line.

#ifdef __GNUC__
#pragma GCC system_header
#endif /* __GNUC__ */

#include <crtdefs.h>

struct _exception;

#pragma pack(push,_CRT_PACKING)

#define _DOMAIN     1   /* domain error in argument */
#define _SING       2   /* singularity */
#define _OVERFLOW   3   /* range overflow */
#define _UNDERFLOW  4   /* range underflow */
#define _TLOSS      5   /* total loss of precision */
#define _PLOSS      6   /* partial loss of precision */

Please refer to this question : https://stackoverflow.com/questions/42231558/mingw-c-wont-compile-j0-funciton

Please fix it or tell me whether should I report the issue to Mingw64/Msys2

Issue submission checklist
berak commented 3 years ago

which mingw version is it ? 8.1.0 here can handle c++14 "out-of-the-box", so you might not need the -DENABLE_CXX11=ON flag i don' have ceres here, but a small example:

#include <math.h>
int main(int argc, char* argv[])
{
    j0(13);
    return 0;
}

g++ my.cpp // compiles fine g++ -std=c++11 my.cpp // error: 'j0' was not declared in this scope

so, can you try, if removing the flag from the cmake cmdline helps ?

garfeng commented 3 years ago

Hello, thank you for your help.

I use the toolchain installed in Msys2.

mingw32 mingw-w64-i686-arm-none-eabi-gcc 10.1.0-2
mingw32 mingw-w64-i686-avr-gcc 8.4.0-4
mingw32 mingw-w64-i686-gcc 10.3.0-5 [installed]
mingw32 mingw-w64-i686-gcc-ada 10.3.0-5
mingw32 mingw-w64-i686-gcc-fortran 10.3.0-5
mingw32 mingw-w64-i686-gcc-libgfortran 10.3.0-5 [installed]
mingw32 mingw-w64-i686-gcc-libs 10.3.0-5 [installed]
mingw32 mingw-w64-i686-gcc-objc 10.3.0-5
mingw32 mingw-w64-i686-libgccjit 10.3.0-5
mingw32 mingw-w64-i686-riscv64-unknown-elf-gcc 10.1.0-2
mingw64 mingw-w64-x86_64-arm-none-eabi-gcc 10.1.0-2
mingw64 mingw-w64-x86_64-avr-gcc 8.4.0-4
mingw64 mingw-w64-x86_64-gcc 10.3.0-5 [installed]
mingw64 mingw-w64-x86_64-gcc-ada 10.3.0-5 [installed]
mingw64 mingw-w64-x86_64-gcc-fortran 10.3.0-5 [installed]
mingw64 mingw-w64-x86_64-gcc-libgfortran 10.3.0-5 [installed]
mingw64 mingw-w64-x86_64-gcc-libs 10.3.0-5 [installed]
mingw64 mingw-w64-x86_64-gcc-objc 10.3.0-5 [installed]
mingw64 mingw-w64-x86_64-libgccjit 10.3.0-5 [installed]
mingw64 mingw-w64-x86_64-riscv64-unknown-elf-gcc 10.1.0-2
ucrt64 mingw-w64-ucrt-x86_64-gcc 10.3.0-5
ucrt64 mingw-w64-ucrt-x86_64-gcc-fortran 10.3.0-5
ucrt64 mingw-w64-ucrt-x86_64-gcc-libgfortran 10.3.0-5
ucrt64 mingw-w64-ucrt-x86_64-gcc-libs 10.3.0-5
ucrt64 mingw-w64-ucrt-x86_64-gcc-objc 10.3.0-5
ucrt64 mingw-w64-ucrt-x86_64-libgccjit 10.3.0-5
msys gcc 10.2.0-1
msys gcc-fortran 10.2.0-1
msys gcc-libs 10.2.0-1 [installed]
msys mingw-w64-cross-gcc 10.2.0-1

8.1.0 here can handle c++14 "out-of-the-box", so you might not need the -DENABLE_CXX11=ON flag

When I remove the -DENABLE_CXX11=ON, the error still appears.

alalek commented 3 years ago

Use make VERBOSE=1 to see actual compiler's command line of failed step (check for -std= option)

superheasy commented 3 years ago

I have the same problem。 Windows 10 x64 ,Msys2 ,g++ 10.3.0,opencv4.5.3 .

I Use make VERBOSE=1

`

$ mingw32-make.exe VERBOSE=1
C:\msys64\mingw64\bin\cmake.exe -SD:\opencv\opencv -BD:\opencv\opencv4_mingw64build --check-build-system CMakeFiles\Makefile.cmake 0 C:\msys64\mingw64\bin\cmake.exe -E cmake_progress_start D:\opencv\opencv4_mingw64build\CMakeFiles D:\opencv\opencv4_mingw64build\CMakeFiles\progress.marks C:/msys64/mingw64/bin/mingw32-make.exe -f CMakeFiles\Makefile2 all mingw32-make[1]: Entering directory 'D:/opencv/opencv4_mingw64build' C:/msys64/mingw64/bin/mingw32-make.exe -f CMakeFiles\gen-pkgconfig.dir\build.make CMakeFiles/gen-pkgconfig.dir/depend mingw32-make[2]: Entering directory 'D:/opencv/opencv4_mingw64build' C:\msys64\mingw64\bin\cmake.exe -E cmake_depends "MinGW Makefiles" D:\opencv\opencv D:\opencv\opencv D:\opencv\opencv4_mingw64build D:\opencv\opencv4_mingw64build D:\opencv\opencv4_mingw64build\CMakeFiles\gen-pkgconfig.dir\DependInfo.cma mingw32-make[2]: Leaving directory 'D:/opencv/opencv4_mingw64build' C:/msys64/mingw64/bin/mingw32-make.exe -f CMakeFiles\gen-pkgconfig.dir\build.make CMakeFiles/gen-pkgconfig.dir/build mingw32-make[2]: Entering directory 'D:/opencv/opencv4_mingw64build' mingw32-make[2]: Nothing to be done for 'CMakeFiles/gen-pkgconfig.dir/build'. mingw32-make[2]: Leaving directory 'D:/opencv/opencv4_mingw64build' [ 0%] Built target gen-pkgconfig

`

……………………………………

…………………………………… `

Consolidate compiler generated dependencies of target multiview mingw32-make[2]: Leaving directory 'D:/opencv/opencv4_mingw64build' C:/msys64/mingw64/bin/mingw32-make.exe -f modules\sfm\src\libmv\libmv\multiview\CMakeFiles\multiview.dir\build.make modules/sfm/src/libmv/libmv/multiview/CMakeFiles/multiview.dir/build mingw32-make[2]: Entering directory 'D:/opencv/opencv4_mingw64build' [ 88%] Building CXX object modules/sfm/src/libmv/libmv/multiview/CMakeFiles/multiview.dir/fundamental.cc.obj cd /d D:\opencv\opencv4_mingw64build\modules\sfm\src\libmv\libmv\multiview && C:/msys64/mingw64/bin/ccache.exe C:\msys64\mingw64\bin\g++.exe -DCERES_EXPORT_INTERNAL_SYMBOLS -DCERES_FOUND=1 -DGFLAGS_IS_A_DLL=1 -DGLOG_NO_ABBREVIATED_SEVERILD=1 -DSTDC_CONSTANT_MACROS -DSTDC_FORMAT_MACROS -D__STDC_LIMIT_MACROS @CMakeFiles/multiview.dir/includes_CXX.rsp -fsigned-char -W -Wall -Werror=return-type -Werror=non-virtual-dtor -Werror=address -Werror=sequence-point -Wformat -Weno-delete-non-virtual-dtor -Wno-comment -Wimplicit-fallthrough=3 -Wno-strict-overflow -fdiagnostics-show-option -Wno-long-long -fomit-frame-pointer -ffunction-sections -fdata-sections -msse -msse2 -msse3 -fvisibility=hidden -fvisibilityeclarations -Wno-unused-but-set-variable -Wno-unused-parameter -Wno-unused-function -Wno-suggest-override -Wno-suggest-override -Wno-class-memaccess -Wno-deprecated-copy -O3 -DNDEBUG -DNDEBUG -std=c++14 -MD -MT modules/sfm/src/libmv/libw.dir\fundamental.cc.obj.d -o CMakeFiles\multiview.dir\fundamental.cc.obj -c D:\opencv\opencv_contrib\modules\sfm\src\libmv_light\libmv\multiview\fundamental.cc In file included from C:/msys64/mingw64/include/ceres/internal/autodiff.h:153, from C:/msys64/mingw64/include/ceres/autodiff_cost_function.h:130, from C:/msys64/mingw64/include/ceres/ceres.h:37, from D:\opencv\opencv_contrib\modules\sfm\src\libmv_light\libmv\multiview\fundamental.cc:24: C:/msys64/mingw64/include/ceres/jet.h: In function 'double ceres::BesselJ0(double)': C:/msys64/mingw64/include/ceres/jet.h:603:10: error: 'j0' was not declared in this scope; did you mean 'V0'? 603 | return j0(x); | ^~ | V0 C:/msys64/mingw64/include/ceres/jet.h: In function 'double ceres::BesselJ1(double)': C:/msys64/mingw64/include/ceres/jet.h:610:10: error: 'j1' was not declared in this scope; did you mean 'V1'? 610 | return j1(x); | ^~ | V1 C:/msys64/mingw64/include/ceres/jet.h: In function 'double ceres::BesselJn(int, double)': C:/msys64/mingw64/include/ceres/jet.h:617:10: error: 'jn' was not declared in this scope; did you mean 'n'? 617 | return jn(n, x); | ^~ | n mingw32-make[2]: [modules\sfm\src\libmv\libmv\multiview\CMakeFiles\multiview.dir\build.make:106: modules/sfm/src/libmv/libmv/multiview/CMakeFiles/multiview.dir/fundamental.cc.obj] Error 1 mingw32-make[2]: Leaving directory 'D:/opencv/opencv4_mingw64build' mingw32-make[1]: [CMakeFiles\Makefile2:8317: modules/sfm/src/libmv/libmv/multiview/CMakeFiles/multiview.dir/all] Error 2 mingw32-make[1]: Leaving directory 'D:/opencv/opencv4_mingw64build' mingw32-make: *** [Makefile:165: all] Error 2 `

I have test g++: this is Ok $ g++ -std=gnu++14 hello.cpp ,but error when ` $ g++ -std=c++14 hello.cpp hello.cpp: In function 'int main(int, char**)': hello.cpp:4:2: error: 'j0' was not declared in this scope 4 | j0(13); | ^~

`


p.s. 
when BUILD_opencv_sfm is off ,I can build successful .
alalek commented 3 years ago

Could you try these options:

superheasy commented 3 years ago

I make all both cmake ... -DOPENCV_EXTRA_CXX_FLAGS=-std=gnu++14 and cmake -DCMAKE_CXX_EXTENSIONS=ON

·

Consolidate compiler generated dependencies of target multiview [ 91%] Building CXX object modules/sfm/src/libmv/libmv/multiview/CMakeFiles/multiview.dir/robust_estimation.cc.obj In file included from D:\opencv\opencv_contrib\modules\sfm\src\libmv_light\libmv\multiview\robust_estimation.cc:26: D:/opencv/opencv_contrib/modules/sfm/src/libmv_light/libmv/multiview/robust_estimation.h:57:8: error: 'uint' does not name a type; did you mean 'rint'? 57 | static uint IterationsRequired(int min_samples, | ^~~~ | rint D:/opencv/opencv_contrib/modules/sfm/src/libmv_light/libmv/multiview/robust_estimation.h: In function 'typename Kernel::Model libmv::Estimate(const Kernel&, const Scorer&, libmv::vector, double, double)': D:/opencv/opencv_contrib/modules/sfm/src/libmv_light/libmv/multiview/robust_estimation.h:138:26: error: there are no arguments to 'IterationsRequired' that depend on a template parameter, so a declaration of 'IterationsRequired' must be available [-fpermissive] 138 | max_iterations = IterationsRequired(min_samples, | ^~~~~~ D:/opencv/opencv_contrib/modules/sfm/src/libmv_light/libmv/multiview/robust_estimation.h:138:26: note: (if you use '-fpermissive', G++ will accept your code, but allowing the use of an undeclared name is deprecated) mingw32-make[2]: [modules\sfm\src\libmv\libmv\multiview\CMakeFiles\multiview.dir\build.make:196: modules/sfm/src/libmv/libmv/multiview/CMakeFiles/multiview.dir/robust_estimation.cc.obj] Error 1 mingw32-make[1]: [CMakeFiles\Makefile2:8224: modules/sfm/src/libmv/libmv/multiview/CMakeFiles/multiview.dir/all] Error 2

·~~~~~~~~ verbose=1

` [ 92%] Building CXX object modules/stitching/CMakeFiles/opencv_stitching.dir/src/seam_finders.cpp.obj cd /d D:\opencv\opencv4_mingw64build\modules\stitching && C:/msys64/mingw64/bin/ccache.exe C:\msys64\mingw64\bin\g++.exe -DCVAPI_EXPORTS -DVK_NO_PROTOTYPES -D_USE_MATH_DEFINES -D_WIN32_WINNT=0x0601 -D__OPENCV_BUILD=1 -DSTDC_CONSTANT_MACROS -DSTDC_FORMAT_MACROS -D__STDC_LIMIT_MACROS @CMakeFiles/opencv_stitching.dir/includes_CXX.rsp -std=gnu++14 -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 -Wsuggest-override -Wno-delete-non-virtual-dtor -Wno-comment -Wimplicit-fallthrough=3 -Wno-strict-overflow -fdiagnostics-show-option -Wno-long-long -fomit-frame-pointer -ffunction-sections -fdata-sections -msse -msse2 -msse3 -fvisibility=hidden -fvisibility-inlines-hidden -fopenmp -O3 -DNDEBUG -DNDEBUG -std=gnu++11 -MD -MT modules/stitching/CMakeFiles/opencv_stitching.dir/src/seam_finders.cpp.obj -MF CMakeFiles\opencv_stitching.dir\src\seam_finders.cpp.obj.d -o CMakeFiles\opencv_stitching.dir\src\seam_finders.cpp.obj -c D:\opencv\opencv\modules\stitching\src\seam_finders.cpp In file included from D:\opencv\opencv_contrib\modules\sfm\src\libmv_light\libmv\multiview\robust_resection.cc:22: D:/opencv/opencv_contrib/modules/sfm/src/libmv_light/libmv/multiview/robust_estimation.h:57:8: error: 'uint' does not name a type; did you mean 'rint'? 57 | static uint IterationsRequired(int min_samples, | ^~~~ | rint D:/opencv/opencv_contrib/modules/sfm/src/libmv_light/libmv/multiview/robust_estimation.h: In function 'typename Kernel::Model libmv::Estimate(const Kernel&, const Scorer&, libmv::vector, double, double)': D:/opencv/opencv_contrib/modules/sfm/src/libmv_light/libmv/multiview/robust_estimation.h:138:26: error: there are no arguments to 'IterationsRequired' that depend on a template parameter, so a declaration of 'IterationsRequired' must be available [-fpermissive] 138 | max_iterations = IterationsRequired(min_samples, | ^~~~~~ D:/opencv/opencv_contrib/modules/sfm/src/libmv_light/libmv/multiview/robust_estimation.h:138:26: note: (if you use '-fpermissive', G++ will accept your code, but allowing the use of an undeclared name is deprecated) D:/opencv/opencv_contrib/modules/sfm/src/libmv_light/libmv/multiview/robust_estimation.h: In instantiation of 'typename Kernel::Model libmv::Estimate(const Kernel&, const Scorer&, libmv::vector, double, double) [with Kernel = libmv::resection::kernel::Kernel; Scorer = libmv::MLEScorer; typename Kernel::Model = Eigen::Matrix<double, 3, 4>]': D:\opencv\opencv_contrib\modules\sfm\src\libmv_light\libmv\multiview\robust_resection.cc:41:50: required from here D:/opencv/opencv_contrib/modules/sfm/src/libmv_light/libmv/multiview/robust_estimation.h:138:44: error: 'IterationsRequired' was not declared in this scope 138 | max_iterations = IterationsRequired(min_samples, | ~~~~^~~ 139 | outliers_probability, | ~~~~~ 140 | best_inlier_ratio); | ~~~~~~ mingw32-make[2]: [modules\sfm\src\libmv\libmv\multiview\CMakeFiles\multiview.dir\build.make:226: modules/sfm/src/libmv/libmv/multiview/CMakeFiles/multiview.dir/robust_resection.cc.obj] Error 1 mingw32-make[2]: Leaving directory 'D:/opencv/opencv4_mingw64build' mingw32-make[1]: [CMakeFiles\Makefile2:8224: modules/sfm/src/libmv/libmv/multiview/CMakeFiles/multiview.dir/all] Error 2 mingw32-make[1]: *** Waiting for unfinished jobs....

`

alalek commented 3 years ago

Now there are several -std options. That isn't good.

g++.exe -std=gnu++14 ... -std=gnu++11 ...

Please try this only:

cmake ... -DCMAKE_CXX_EXTENSIONS=ON -DCMAKE_CXX_STANDARD=14

(please check installed Ceres version and its prerequisites about required C++ mode)

garfeng commented 3 years ago

Now there are several -std options. That isn't good.

g++.exe -std=gnu++14 ... -std=gnu++11 ...

Please try this only:

cmake ... -DCMAKE_CXX_EXTENSIONS=ON -DCMAKE_CXX_STANDARD=14

(please check installed Ceres version and its prerequisites about required C++ mode)

@alalek thank you for your answer.

cmake ... -DCMAKE_CXX_EXTENSIONS=ON -DCMAKE_CXX_STANDARD=14

works!!!