奇怪的opencv编译错误

时间:2014-05-28 03:52:10

标签: c++ opencv compilation

所以我要做的就是使用opencv-2.3编译我的程序。这一切都在我正确安装所有内容之下。

My Main非常简单:

#include <iostream>
#include <opencv/cv.h>
int main(int argv, char** argc){
   std::cout << "Hello World" << std::endl;
   return 0;
}

我的MakeFile非常简单。

g++ main.cpp `pkg-config opencv --cflags --libs`

错误实在令人困惑:

 make
g++ main.cpp \
`pkg-config opencv --cflags --libs`
In file included from /usr/include/c++/4.6/bits/stl_algo.h:62:0,
             from /usr/include/c++/4.6/algorithm:63,
             from /usr/local/include/opencv2/core/core.hpp:56,
             from /usr/local/include/opencv/cv.h:64,
             from main.cpp:8:
/usr/include/c++/4.6/bits/algorithmfwd.h:358:41: error: macro "max" passed 3 arguments, but takes just 2
/usr/include/c++/4.6/bits/algorithmfwd.h:369:41: error: macro "min" passed 3 arguments, but takes just 2
In file included from /usr/include/c++/4.6/bits/stl_algo.h:62:0,
             from /usr/include/c++/4.6/algorithm:63,
             from /usr/local/include/opencv2/core/core.hpp:56,
             from /usr/local/include/opencv/cv.h:64,
             from main.cpp:8:
/usr/include/c++/4.6/bits/algorithmfwd.h:354:5: error: expected unqualified-id before ‘const’
/usr/include/c++/4.6/bits/algorithmfwd.h:354:5: error: expected ‘)’ before ‘const’
/usr/include/c++/4.6/bits/algorithmfwd.h:354:5: error: expected ‘)’ before ‘const’
/usr/include/c++/4.6/bits/algorithmfwd.h:354:5: error: expected initializer before ‘const’
/usr/include/c++/4.6/bits/algorithmfwd.h:358:5: error: template declaration of ‘const _Tp& std::max’
/usr/include/c++/4.6/bits/algorithmfwd.h:365:5: error: expected unqualified-id before ‘const’
/usr/include/c++/4.6/bits/algorithmfwd.h:365:5: error: expected ‘)’ before ‘const’
/usr/include/c++/4.6/bits/algorithmfwd.h:365:5: error: expected ‘)’ before ‘const’
/usr/include/c++/4.6/bits/algorithmfwd.h:365:5: error: expected initializer before ‘const’
/usr/include/c++/4.6/bits/algorithmfwd.h:369:5: error: template declaration of ‘const _Tp& std::min’
In file included from /usr/include/c++/4.6/algorithm:63:0,
             from /usr/local/include/opencv2/core/core.hpp:56,
             from /usr/local/include/opencv/cv.h:64,
             from main.cpp:8:
/usr/include/c++/4.6/bits/stl_algo.h: In function ‘void std::__merge_sort_loop(_RandomAccessIterator1, _RandomAccessIterator1, _RandomAccessIterator2, _Distance)’:
/usr/include/c++/4.6/bits/stl_algo.h:3285:26: error: expected unqualified-id before ‘(’ token
/usr/include/c++/4.6/bits/stl_algo.h: In function ‘void std::__merge_sort_loop(_RandomAccessIterator1, _RandomAccessIterator1, _RandomAccessIterator2, _Distance, _Compare)’:
/usr/include/c++/4.6/bits/stl_algo.h:3308:26: error: expected unqualified-id before ‘(’ token
In file included from /usr/local/include/opencv2/core/core.hpp:59:0,
             from /usr/local/include/opencv/cv.h:64,
             from main.cpp:8:
/usr/include/c++/4.6/complex: In function ‘_Tp std::__complex_abs(const std::complex<_Tp>&)’:`
/usr/include/c++/4.6/complex:571:28: error: expected unqualified-id before ‘(’ token
In file included from /usr/include/c++/4.6/vector:65:0,
             from /usr/local/include/opencv2/core/core.hpp:63,
             from /usr/local/include/opencv/cv.h:64,
             from main.cpp:8:
/usr/include/c++/4.6/bits/stl_vector.h: In member function ‘std::vector<_Tp, _Alloc>::size_type std::vector<_Tp, _Alloc>::_M_check_len(std::vector<_Tp, _Alloc>::size_type, const char*) const’:
/usr/include/c++/4.6/bits/stl_vector.h:1244:40: error: expected unqualified-id before ‘(’ token
In file included from /usr/include/c++/4.6/vector:66:0,
             from /usr/local/include/opencv2/core/core.hpp:63,
             from /usr/local/include/opencv/cv.h:64,
             from main.cpp:8:
/usr/include/c++/4.6/bits/stl_bvector.h: In member function ‘std::vector<bool, _Alloc>::size_type std::vector<bool, _Alloc>::_M_check_len(std::vector<bool, _Alloc>::size_type, const char*) const’:
/usr/include/c++/4.6/bits/stl_bvector.h:1026:45: error: expected unqualified-id before ‘(’ token

现在,当我在终端中点击pkg-config --cflags --libs opencv时,我得到了所有lib和.hpp等文件的正确位置。所以我不知道这里发生了什么。 谢谢你的帮助!!

1 个答案:

答案 0 :(得分:0)

可能是由于使用旧的C标头引起的。如果我没记错的话,新的位于<opencv2/opencv.hpp>