Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

error: no match for 'operator[]' (operand types are 'const google::protobuf::RepeatedField<long int>' and 'int') #18110

Closed
abagali1 opened this issue Aug 17, 2020 · 10 comments
Labels
category: build/install confirmed There is stable reproducer / investigation complete platform: linux

Comments

@abagali1
Copy link

System information (version)
  • OpenCV => 4.3.0
  • Operating System / Platform => Ubuntu 18.04.5
  • Compiler => cmake 3.10.2, ninja 1.8.2
Detailed description

I was packaging OpenCV 4.3.0 for debian using the source here but when compiling I get this error

[562/1424] Building CXX object modules/dnn/CMakeFiles/opencv_dnn.dir/src/onnx/onnx_importer.cpp.o
FAILED: modules/dnn/CMakeFiles/opencv_dnn.dir/src/onnx/onnx_importer.cpp.o 
/usr/bin/c++  -DCVAPI_EXPORTS -DCV_OCL4DNN=1 -DHAVE_PROTOBUF=1 -DOPENCV_DNN_EXTERNAL_PROTOBUF=1 -DPROTOBUF_INLINE_NOT_IN_HEADERS=0 -D_USE_MATH_DEFINES -D__OPENCV_BUILD=1 -D__STDC_CONSTANT_MACROS -D__STDC_FORMAT_MACROS -D__STDC_LIMIT_MACROS -I. -isystem /usr/include/gdal -I../modules/dnn/include -Imodules/dnn -I../modules/core/include -I../modules/imgproc/include -I/usr/include/CL -isystem /usr/include/eigen3 -fsigned-char -W -Wall -Werror=return-type -Werror=non-virtual-dtor -Werror=address -Werror=sequence-point -Wformat -Werror=format-security -Wundef -Winit-self -Wpointer-arith -Wsign-promo -Wuninitialized -Winit-self -Wsuggest-override -Wno-delete-non-virtual-dtor -Wno-comment -Wimplicit-fallthrough=3 -Wno-strict-overflow -fdiagnostics-show-option -Wno-long-long -pthread -fomit-frame-pointer -ffunction-sections -fdata-sections  -msse -msse2 -fvisibility=hidden -fvisibility-inlines-hidden -Wno-deprecated -Wno-missing-declarations -Wno-shadow -Wno-unused-parameter -Wno-sign-compare -Wno-invalid-offsetof   -DNDEBUG -fPIC   -std=c++11 -MD -MT modules/dnn/CMakeFiles/opencv_dnn.dir/src/onnx/onnx_importer.cpp.o -MF modules/dnn/CMakeFiles/opencv_dnn.dir/src/onnx/onnx_importer.cpp.o.d -o modules/dnn/CMakeFiles/opencv_dnn.dir/src/onnx/onnx_importer.cpp.o -c ../modules/dnn/src/onnx/onnx_importer.cpp
In file included from ../modules/dnn/src/onnx/onnx_importer.cpp:29:0:
../modules/dnn/src/onnx/onnx_graph_simplifier.hpp: In instantiation of 'void cv::dnn::dnn4_v20200310::convertInt64ToInt32(const T1&, T2&, int) [with T1 = google::protobuf::RepeatedField<long int>; T2 = std::vector<int>]':
../modules/dnn/src/onnx/onnx_importer.cpp:151:45:   required from here
../modules/dnn/src/onnx/onnx_graph_simplifier.hpp:31:16: error: no match for 'operator[]' (operand types are 'const google::protobuf::RepeatedField<long int>' and 'int')
         if (src[i] < std::numeric_limits<int32_t>::min() || src[i] > std::numeric_limits<int32_t>::max()) {
             ~~~^
../modules/dnn/src/onnx/onnx_graph_simplifier.hpp:31:64: error: no match for 'operator[]' (operand types are 'const google::protobuf::RepeatedField<long int>' and 'int')
         if (src[i] < std::numeric_limits<int32_t>::min() || src[i] > std::numeric_limits<int32_t>::max()) {
                                                             ~~~^
../modules/dnn/src/onnx/onnx_graph_simplifier.hpp:34:44: error: no match for 'operator[]' (operand types are 'const google::protobuf::RepeatedField<long int>' and 'int')
         dst[i] = saturate_cast<int32_t>(src[i]);
                                         ~~~^
ninja: build stopped: subcommand failed.

Reproduced this error using the OpenCV 4.3 Release using the same build flags. I have exhausted multiple different versions of protoc(default 3.0.0, 3.5.1, 3.10.0) and I tried setting DBUILD_PROTOC=ON which also fails with a separate error (no file "sys/videoio.h").

CMake Flags:

-GNinja -DANT_EXECUTABLE=/usr/bin/ant -DBUILD_EXAMPLES=OFF -DBUILD_PROTOBUF=OFF -DBUILD_PERF_TESTS=OFF -DBUILD_opencv_dnn=ON -DBUILD_opencv_dnn_modern=ON -DBUILD_opencv_face=ON -DCMAKE_BUILD_TYPE=Release -DCMAKE_CXX_FLAGS_RELEASE="" -DCMAKE_C_FLAGS_RELEASE="" -DCMAKE_EXE_LINKER_FLAGS_RELEASE="" -DCMAKE_INSTALL_LIBDIR="lib/x86_64-linux-gnu" -DCMAKE_INSTALL_PREFIX=/usr -DCMAKE_SKIP_RPATH=ON -DCMAKE_VERBOSE_MAKEFILE=ON -DENABLE_PRECOMPILED_HEADERS=OFF -DINSTALL_C_EXAMPLES=ON -DINSTALL_PYTHON_EXAMPLES=ON -DOPENCL_INCLUDE_DIR:PATH="/usr/include/CL/" -DOPENCV_EXTRA_MODULES_PATH="/root/opencv/contrib/modules" -DOPENCV_MATHJAX_RELPATH=/usr/share/javascript/mathjax/ -DOPENCV_SKIP_PYTHON_LOADER=ON -DOPENCV_GENERATE_PKGCONFIG=ON -DOPENCV_LAPACK_FIND_PACKAGE_ONLY=ON -DOpenGL_GL_PREFERENCE=GLVND -DPROTOBUF_UPDATE_FILES=ON -DWITH_ADE=OFF -DWITH_CAROTENE=OFF -DWITH_CUDA=OFF -DWITH_EIGEN=ON -DWITH_FFMPEG=ON -DWITH_GDAL=ON -DWITH_GDCM=ON -DWITH_GSTREAMER=ON -DWITH_GTK=ON -DWITH_IPP=OFF -DWITH_ITT=OFF -DWITH_JASPER=OFF -DWITH_JPEG=ON -DWITH_LAPACK=ON -DWITH_NGRAPH=OFF -DWITH_OPENCL=ON -DWITH_OPENEXR=ON -DWITH_OPENGL=ON -DWITH_PNG=ON -DWITH_PROTOBUF=ON -DWITH_PVAPI=ON -DWITH_QT=OFF -DWITH_QUIRC=OFF -DWITH_TIFF=ON -DWITH_UNICAP=OFF -DWITH_VTK=ON -DWITH_XINE=OFF  -DCPU_BASELINE="SSE2" -DCPU_BASELINE_DISABLE="SSE3" -DWITH_TBB=ON -DWITH_1394=ON -DWITH_V4L=ON

CMakeOutput.log
CMakeError.log

@asmorkalov asmorkalov added category: build/install platform: linux confirmed There is stable reproducer / investigation complete labels Aug 17, 2020
@asmorkalov
Copy link
Contributor

I reproduced the issue on Ubuntu 18.04 with protoc for official repository.

@abagali1
Copy link
Author

Forgot to mention this but the same configuration works on Ubuntu 20.04 which has protoc 3.6.1. Installed 3.6.1 on 18.04 but the build still failed.

@abagali1
Copy link
Author

@asmorkalov thanks for the confirm, do you have a fix?

@asmorkalov
Copy link
Contributor

@abagali1 Not yet.

@alalek
Copy link
Member

alalek commented Aug 18, 2020

Please provide information about used protobuf version.
Ensure that you don't have mess between different versions (gcc -H option may help).


error: no match for 'operator[]'

This code should handle that:
https://github.com/protocolbuffers/protobuf/blame/214c77e1b76e63e512bd675d1c300c80438642b6/src/google/protobuf/repeated_field.h#L190-L191


../modules/dnn/src/onnx/onnx_graph_simplifier.hpp:31:16
if (src[i] < std::numeric_limits<int32_t>::min() || src[i] > std::numeric_limits<int32_t>::max()) {

This part has been refactored by #16985 (released with 3.4.11 / 4.4.0):
https://github.com/opencv/opencv/pull/16985/files#diff-d2601e904d1e5a86b49ac68f950e44a6L31

@abagali1
Copy link
Author

I am packaging within docker containers and made sure I only had 1 version present at a time. I believe the 18.04 default is 3.0.0, but I also tried with 3.5.1, 3.6.1, and 3.10.0

@abagali1
Copy link
Author

This code should handle that:
https://github.com/protocolbuffers/protobuf/blame/214c77e1b76e63e512bd675d1c300c80438642b6/src/google/protobuf/repeated_field.h#L190-L191

How would I go about changing this in my build? Should I build the lastest protobuf and install it from source? While changing protobuf versions I encountered errors similar to those in opencv/opencv_contrib#2408

@alalek
Copy link
Member

alalek commented Aug 18, 2020

OpenCV uses protobuf 3.5.x.
Other versions are not tested, so they may not work.

changing this in my build

At first, check which version of this file do you have.

Should I build the lastest protobuf and install it from source

OpenCV already has builtin protobuf sources with extra patches. Just remove extra "protobuf" related CMake options.
(not sure if this may conflict with packaging policies)

@abagali1
Copy link
Author

Ok thank you, I will try again with protobuf 3.5.x and follow up.

Just remove extra "protobuf" related CMake options.

Do you see any such flags in my issue description?

@abagali1
Copy link
Author

abagali1 commented Aug 19, 2020

Installation of protobuf 3.5.1 fixes this, maybe error in the original install process.
I installed protobuf 3.5.1 from this release

Install steps

./autogen.sh
./configure
make
make install

Thanks for all your help, closing.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
category: build/install confirmed There is stable reproducer / investigation complete platform: linux
Projects
None yet
Development

No branches or pull requests

3 participants