我正在尝试从他们的网站http://www.boost.org/doc/libs/1_59_0/libs/gil/example/dynamic_image.cpp
建立一个提升示例代码在Ubuntu 14.04和G ++ 4.8上。
以下代码:
#include <boost/mpl/vector.hpp>
#include <boost/gil/extension/dynamic_image/any_image.hpp>
#include <boost/gil/extension/io/jpeg_dynamic_io.hpp>
int main() {
using namespace boost::gil;
typedef boost::mpl::vector<gray8_image_t, rgb8_image_t, gray16_image_t, rgb16_image_t> my_images_t;
any_image<my_images_t> dynamic_img;
jpeg_read_image("test.jpg",dynamic_img);
// Save the image upside down, preserving its native color space and channel depth
jpeg_write_view("out-dynamic_image.jpg",flipped_up_down_view(const_view(dynamic_img)));
return 0;
}
编译命令:
g++ -o dynamic_image.o dynamic_image.cpp -Iboost -Iimagelib/jpeg-6b -Iimagelib/libpng-1.6.13
产生错误:
In file included from /usr/include/c++/4.8/vector:64:0,
from kboost/boost/gil/extension/io/jpeg_io_private.hpp:24,
from kboost/boost/gil/extension/io/jpeg_io.hpp:32,
from kboost/boost/gil/extension/io/jpeg_dynamic_io.hpp:31,
from dynamic_image.cpp:20:
/usr/include/c++/4.8/bits/stl_vector.h:117:7: error: ‘std::_Vector_base<_Tp, _Alloc>::_Tp_alloc_type& std::_Vector_base<_Tp, _Alloc>::_M_get_Tp_allocator()’ cannot be overloaded
_M_get_Tp_allocator() const _GLIBCXX_NOEXCEPT
^
/usr/include/c++/4.8/bits/stl_vector.h:113:7: error: with ‘std::_Vector_base<_Tp, _Alloc>::_Tp_alloc_type& std::_Vector_base<_Tp, _Alloc>::_M_get_Tp_allocator()’
_M_get_Tp_allocator() _GLIBCXX_NOEXCEPT
^
/usr/include/c++/4.8/bits/stl_vector.h:547:7: error: ‘std::vector<_Tp, _Alloc>::const_iterator std::vector<_Tp, _Alloc>::begin()’ cannot be overloaded
begin() const _GLIBCXX_NOEXCEPT
^
/usr/include/c++/4.8/bits/stl_vector.h:538:7: error: with ‘std::vector<_Tp, _Alloc>::iterator std::vector<_Tp, _Alloc>::begin()’
begin() _GLIBCXX_NOEXCEPT
^
/usr/include/c++/4.8/bits/stl_vector.h:565:7: error: ‘std::vector<_Tp, _Alloc>::const_iterator std::vector<_Tp, _Alloc>::end()’ cannot be overloaded
end() const _GLIBCXX_NOEXCEPT
^
/usr/include/c++/4.8/bits/stl_vector.h:556:7: error: with ‘std::vector<_Tp, _Alloc>::iterator std::vector<_Tp, _Alloc>::end()’
end() _GLIBCXX_NOEXCEPT
^
/usr/include/c++/4.8/bits/stl_vector.h:583:7: error: ‘std::vector<_Tp, _Alloc>::const_reverse_iterator std::vector<_Tp, _Alloc>::rbegin()’ cannot be overloaded
rbegin() const _GLIBCXX_NOEXCEPT
^
/usr/include/c++/4.8/bits/stl_vector.h:574:7: error: with ‘std::vector<_Tp, _Alloc>::reverse_iterator std::vector<_Tp, _Alloc>::rbegin()’
rbegin() _GLIBCXX_NOEXCEPT
^
/usr/include/c++/4.8/bits/stl_vector.h:601:7: error: ‘std::vector<_Tp, _Alloc>::const_reverse_iterator std::vector<_Tp, _Alloc>::rend()’ cannot be overloaded
rend() const _GLIBCXX_NOEXCEPT
我相当肯定这个问题与示例代码无关,所以我做错了什么?我最好的猜测是我使用了错误的库或编译器配置错误...
更新 添加-std = c ++ 11标志修复了我的错误。现在我收到以下错误:
In file included from kboost/boost/config.hpp:61:0,
from kboost/boost/mpl/aux_/config/msvc.hpp:19,
from kboost/boost/mpl/aux_/config/adl.hpp:17,
from kboost/boost/mpl/aux_/adl_barrier.hpp:17,
from kboost/boost/mpl/bool_fwd.hpp:17,
from kboost/boost/mpl/bool.hpp:17,
from kboost/boost/mpl/aux_/na.hpp:17,
from kboost/boost/mpl/vector.hpp:19,
from dynamic_image.cpp:18:
kboost/boost/gil/extension/io/jpeg_io_private.hpp:37:45: error: ISO C++ forbids in-class initialization of non-const static member ‘boost::gil::detail::jpeg_read_support_private<Channel, ColorSpace>::is_supported’
BOOST_STATIC_CONSTANT(bool,is_supported=false);
^
kboost/boost/gil/extension/io/jpeg_io_private.hpp:38:52: error: ISO C++ forbids in-class initialization of non-const static member ‘boost::gil::detail::jpeg_read_support_private<Channel, ColorSpace>::color_type’
BOOST_STATIC_CONSTANT(J_COLOR_SPACE,color_type=JCS_UNKNOWN);
^
G ++版
g++ (Ubuntu 4.8.4-2ubuntu1~14.04) 4.8.4
Copyright (C) 2013 Free Software Foundation, Inc.
This is free software; see the source for copying conditions. There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.