https://gcc.gnu.org/bugzilla/show_bug.cgi?id=118964

            Bug ID: 118964
           Summary: include <opencv2/opencv.hpp> in the module causes a
                    compilation error
           Product: gcc
           Version: 15.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: printfne at gmail dot com
  Target Milestone: ---

Created attachment 60553
  --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=60553&action=edit
Source code and error information

When I tried to build my code on gcc14, I got an internal compiler error. I
built gcc15 for this purpose, and a new compilation error occurred. This code
can be compiled using clang19, so I'm not sure if my code or the code in the
opencv library doesn't follow the c++ standard or if gcc's support for modules
is inadequate. The error message is summarized as follows:
包含于文件 /usr/include/opencv2/core.hpp:57,
        于 /usr/include/opencv2/opencv.hpp:52,
        于 /home/yongheng/Projects/untitled/Image.ixx:7:
/usr/include/opencv2/core/types.hpp:279:9: 错误:‘template<class _Tp> _Tp
cv::Point3_<_Tp>::dot(const cv::Point3_<_Tp>&) const’ exposes TU-local entity
‘template<class _Tp> _Tp cv::saturate_cast(hfloat)’
  279 |     _Tp dot(const Point3_& pt) const;
      |         ^~~
包含于文件 /usr/include/opencv2/core/matx.hpp:54,
        于 /usr/include/opencv2/core.hpp:56:
/usr/include/opencv2/core/saturate.hpp:161:42: 附注:‘template<class _Tp> _Tp
cv::saturate_cast(hfloat)’ declared with internal linkage
  161 | template<typename _Tp> static inline _Tp saturate_cast(hfloat v) {
return saturate_cast<_Tp>((float)v); }
      |                                          ^~~~~~~~~~~~~
包含于文件 /usr/include/opencv2/core.hpp:58:
/usr/include/opencv2/core/mat.hpp:343:28: 错误:‘template<class _Tp>
cv::_OutputArray::_OutputArray(const std::vector<std::vector<_Tp> >&)’ exposes
TU-local entity ‘template<class _Tp, int m, int n> cv::MatExpr
cv::operator+(const Matx<_Tp, m, n>&, const Mat&)’
  343 |     template<typename _Tp> _OutputArray(const
std::vector<std::vector<_Tp> >& vec);
      |                            ^~~~~~~~~~~~
/usr/include/opencv2/core/mat.hpp:3656:9: 附注:‘template<class _Tp, int m, int n>
cv::MatExpr cv::operator+(const Matx<_Tp, m, n>&, const Mat&)’ declared with
internal linkage
 3656 | MatExpr operator + (const Matx<_Tp, m, n>& a, const Mat& b) { return
Mat(a) + b; }
      |         ^~~~~~~~
/usr/include/opencv2/core/mat.hpp:2343:12: 错误:‘template<class _Tp> size_t
cv::Mat_<_Tp>::elemSize1() const’ exposes TU-local entity ‘template<class _Tp,
int m, int n> cv::MatExpr cv::operator/(const Matx<_Tp, m, n>&, const Mat&)’
 2343 |     size_t elemSize1() const;
      |            ^~~~~~~~~
/usr/include/opencv2/core/mat.hpp:3698:9: 附注:‘template<class _Tp, int m, int n>
cv::MatExpr cv::operator/(const Matx<_Tp, m, n>&, const Mat&)’ declared with
internal linkage
 3698 | MatExpr operator / (const Matx<_Tp, m, n>& a, const Mat& b) { return
Mat(a) / b; }
      |         ^~~~~~~~
/usr/include/opencv2/core/mat.hpp:2347:12: 错误:‘template<class _Tp> size_t
cv::Mat_<_Tp>::step1(int) const’ exposes TU-local entity ‘template<class _Tp,
int m, int n> cv::MatExpr cv::operator/(const Matx<_Tp, m, n>&, const Mat&)’
 2347 |     size_t step1(int i=0) const;
      |            ^~~~~
/usr/include/opencv2/core/mat.hpp:3698:9: 附注:‘template<class _Tp, int m, int n>
cv::MatExpr cv::operator/(const Matx<_Tp, m, n>&, const Mat&)’ declared with
internal linkage
 3698 | MatExpr operator / (const Matx<_Tp, m, n>& a, const Mat& b) { return
Mat(a) / b; }


Reproduction step:
mkdir build && cd build  
cmake .. -G Ninja  
cmake --build .  

gcc version    : gcc 15.0.1
cmake version  : cmake 3.31.5-1
ninja version  : ninja 1.12.1-2
opencv version : opencv 4.11.0-3

Reply via email to