Boost gil读取图像错误
Boost gil read image errors
我想编写简单的程序来使用 boost::gil 读取和编辑图像。读取图像功能总是出错。我继续在 boost 站点上找到的教程。
#include <iostream>
#include <boost/gil/gil_all.hpp>
#include <boost/gil/extension/io/jpeg_io.hpp>
#include <boost/gil/extension/dynamic_image/any_image.hpp>
#include <boost/gil/channel.hpp>
#include <boost/mpl/vector.hpp>
int main(int argc, char *argv[])
{
namespace bg = boost::gil;
static const std::string resources_dir = "../resources";
static const std::string filename = "face.jpg";
typedef boost::mpl::vector<bg::gray8_image_t, bg::gray16_image_t, bg::rgb8_image_t, bg::rgb16_image_t> my_img_types;
bg::any_image<my_img_types> runtime_image;
try{
bg::jpeg_read_image(resources_dir + filename, runtime_image);
} catch (const std::ios_base::failure &e) {
std::cout << e.what() << std::endl;
}
return 0;
}
错误很长,不知道哪里出了问题。似乎将不受支持的图像类型传递到图像模板中,但无论参数如何,它都会显示 - 我也尝试传递一种类型。
[ 50%] Building CXX object src/CMakeFiles/edges.dir/main.cpp.o
In file included from /usr/include/boost/config.hpp:57:0,
from /usr/include/boost/gil/gil_config.hpp:24,
from /usr/include/boost/gil/gil_all.hpp:25,
from /home/mateusz/projects/edges1/src/main.cpp:2:
/usr/include/boost/gil/extension/io/jpeg_io.hpp: In instantiation of ‘const bool boost::gil::jpeg_read_support<boost::gil::any_image_view<boost::mpl::v_item<boost::gil::image_view<boost::gil::memory_based_2d_locator<boost::gil::memory_based_step_iterator<boost::gil::pixel<short unsigned int, boost::gil::layout<boost::mpl::vector3<boost::gil::red_t, boost::gil::green_t, boost::gil::blue_t> > >*> > >, boost::mpl::v_item<boost::gil::image_view<boost::gil::memory_based_2d_locator<boost::gil::memory_based_step_iterator<boost::gil::pixel<unsigned char, boost::gil::layout<boost::mpl::vector3<boost::gil::red_t, boost::gil::green_t, boost::gil::blue_t> > >*> > >, boost::mpl::v_item<boost::gil::image_view<boost::gil::memory_based_2d_locator<boost::gil::memory_based_step_iterator<boost::gil::pixel<short unsigned int, boost::gil::layout<boost::mpl::vector1<boost::gil::gray_color_t> > >*> > >, boost::mpl::v_item<boost::gil::image_view<boost::gil::memory_based_2d_locator<boost::gil::memory_based_step_iterator<boost::gil::pixel<unsigned char, boost::gil::layout<boost::mpl::vector1<boost::gil::gray_color_t> > >*> > >, boost::mpl::vector0<mpl_::na>, 0>, 0>, 0>, 0> > >::is_supported’:
/usr/include/boost/gil/extension/io/jpeg_io.hpp:91:5: required from ‘void boost::gil::jpeg_read_image(const char*, Image&) [with Image = boost::gil::any_image<boost::mpl::vector<boost::gil::image<boost::gil::pixel<unsigned char, boost::gil::layout<boost::mpl::vector1<boost::gil::gray_color_t> > >, false, std::allocator<unsigned char> >, boost::gil::image<boost::gil::pixel<short unsigned int, boost::gil::layout<boost::mpl::vector1<boost::gil::gray_color_t> > >, false, std::allocator<unsigned char> >, boost::gil::image<boost::gil::pixel<unsigned char, boost::gil::layout<boost::mpl::vector3<boost::gil::red_t, boost::gil::green_t, boost::gil::blue_t> > >, false, std::allocator<unsigned char> >, boost::gil::image<boost::gil::pixel<short unsigned int, boost::gil::layout<boost::mpl::vector3<boost::gil::red_t, boost::gil::green_t, boost::gil::blue_t> > >, false, std::allocator<unsigned char> > > >]’
/usr/include/boost/gil/extension/io/jpeg_io.hpp:101:40: required from ‘void boost::gil::jpeg_read_image(const string&, Image&) [with Image = boost::gil::any_image<boost::mpl::vector<boost::gil::image<boost::gil::pixel<unsigned char, boost::gil::layout<boost::mpl::vector1<boost::gil::gray_color_t> > >, false, std::allocator<unsigned char> >, boost::gil::image<boost::gil::pixel<short unsigned int, boost::gil::layout<boost::mpl::vector1<boost::gil::gray_color_t> > >, false, std::allocator<unsigned char> >, boost::gil::image<boost::gil::pixel<unsigned char, boost::gil::layout<boost::mpl::vector3<boost::gil::red_t, boost::gil::green_t, boost::gil::blue_t> > >, false, std::allocator<unsigned char> >, boost::gil::image<boost::gil::pixel<short unsigned int, boost::gil::layout<boost::mpl::vector3<boost::gil::red_t, boost::gil::green_t, boost::gil::blue_t> > >, false, std::allocator<unsigned char> > > >; std::string = std::basic_string<char>]’
/home/mateusz/projects/edges1/src/main.cpp:18:64: required from here
/usr/include/boost/gil/extension/io/jpeg_io.hpp:40:5: error: invalid use of incomplete type ‘struct boost::gil::channel_type<boost::gil::any_image_view<boost::mpl::v_item<boost::gil::image_view<boost::gil::memory_based_2d_locator<boost::gil::memory_based_step_iterator<boost::gil::pixel<short unsigned int, boost::gil::layout<boost::mpl::vector3<boost::gil::red_t, boost::gil::green_t, boost::gil::blue_t> > >*> > >, boost::mpl::v_item<boost::gil::image_view<boost::gil::memory_based_2d_locator<boost::gil::memory_based_step_iterator<boost::gil::pixel<unsigned char, boost::gil::layout<boost::mpl::vector3<boost::gil::red_t, boost::gil::green_t, boost::gil::blue_t> > >*> > >, boost::mpl::v_item<boost::gil::image_view<boost::gil::memory_based_2d_locator<boost::gil::memory_based_step_iterator<boost::gil::pixel<short unsigned int, boost::gil::layout<boost::mpl::vector1<boost::gil::gray_color_t> > >*> > >, boost::mpl::v_item<boost::gil::image_view<boost::gil::memory_based_2d_locator<boost::gil::memory_based_step_iterator<boost::gil::pixel<unsigned char, boost::gil::layout<boost::mpl::vector1<boost::gil::gray_color_t> > >*> > >, boost::mpl::vector0<mpl_::na>, 0>, 0>, 0>, 0> > >’
BOOST_STATIC_CONSTANT(bool,is_supported=
^
In file included from /usr/include/boost/gil/algorithm.hpp:25:0,
from /usr/include/boost/gil/gil_all.hpp:27,
from /home/mateusz/projects/edges1/src/main.cpp:2:
/usr/include/boost/gil/gil_concept.hpp:49:30: error: declaration of ‘struct boost::gil::channel_type<boost::gil::any_image_view<boost::mpl::v_item<boost::gil::image_view<boost::gil::memory_based_2d_locator<boost::gil::memory_based_step_iterator<boost::gil::pixel<short unsigned int, boost::gil::layout<boost::mpl::vector3<boost::gil::red_t, boost::gil::green_t, boost::gil::blue_t> > >*> > >, boost::mpl::v_item<boost::gil::image_view<boost::gil::memory_based_2d_locator<boost::gil::memory_based_step_iterator<boost::gil::pixel<unsigned char, boost::gil::layout<boost::mpl::vector3<boost::gil::red_t, boost::gil::green_t, boost::gil::blue_t> > >*> > >, boost::mpl::v_item<boost::gil::image_view<boost::gil::memory_based_2d_locator<boost::gil::memory_based_step_iterator<boost::gil::pixel<short unsigned int, boost::gil::layout<boost::mpl::vector1<boost::gil::gray_color_t> > >*> > >, boost::mpl::v_item<boost::gil::image_view<boost::gil::memory_based_2d_locator<boost::gil::memory_based_step_iterator<boost::gil::pixel<unsigned char, boost::gil::layout<boost::mpl::vector1<boost::gil::gray_color_t> > >*> > >, boost::mpl::vector0<mpl_::na>, 0>, 0>, 0>, 0> > >’
template <typename T> struct channel_type;
我也是新手 CMakeLists.txt,所以我包含了这些文件。主文件夹中的 CMakeLists:
cmake_minimum_required(VERSION 2.8)
project(edges1)
set(CMAKE_BUILD_TYPE "Debug")
add_subdirectory(src)
set(EXECUTABLE_OUTPUT_PATH ${PROJECT_BINARY_DIR})
set(LIBRARY_OUTPUT_PATH ${PROJECT_BINARY_DIR})
CMakeLists.txt 在 src 文件夹中:
set(SOURCES main.cpp)
set(EXECUTABLE_OUTPUT_PATH ${PROJECT_BINARY_DIR})
set(LIBRARY_OUTPUT_PATH ${PROJECT_BINARY_DIR})
include_directories(${CMAKE_SOURCE_DIR}/include)
find_package(Boost REQUIRED COMPONENTS)
include_directories(${BOOST_INCLUDE_DIRS})
#link_directoires(${CMAKE_SOURCE_ROOT}/lib)
#link_directoires(${LIBRARY_OUTPUT_PATH})
add_executable(edges ${SOURCES})
使用 read_and_convert_image 给出其他错误...
编辑:
已在 src 目录中安装 libjpeg、CMakeLists:
set(SOURCES main.cpp)
set(EXECUTABLE_OUTPUT_PATH ${PROJECT_BINARY_DIR})
set(LIBRARY_OUTPUT_PATH ${PROJECT_BINARY_DIR})
include_directories(${CMAKE_SOURCE_DIR}/include)
add_executable(edges ${SOURCES})
find_package(Boost REQUIRED COMPONENTS)
IF(BOOST_FOUND)
target_link_libraries(edges Boost::boost)
ENDIF()
find_package(JPEG REQUIRED)
IF(JPEG_FOUND)
include_directories(${JPEG_INCLUDE_DIR})
target_link_libraries(edges ${JPEG_INCLUDE_DIR})
ENDIF()
cmake 命令:
cmake -DJPEG_LIBRARY:PATH=/usr/lib/x86_64-linux-gnu/libjpeg.so --libdir=/usr/lib64 ..
制作后:
[ 50%] Linking CXX executable ../edges
CMakeFiles/edges.dir/main.cpp.o: In function `boost::gil::detail::jpeg_reader::init()':
/usr/include/boost/gil/extension/io/jpeg_io_private.hpp:89: undefined reference to `jpeg_std_error'
/usr/include/boost/gil/extension/io/jpeg_io_private.hpp:90: undefined reference to `jpeg_CreateDecompress'
/usr/include/boost/gil/extension/io/jpeg_io_private.hpp:91: undefined reference to `jpeg_stdio_src'
/usr/include/boost/gil/extension/io/jpeg_io_private.hpp:92: undefined reference to `jpeg_read_header'
CMakeFiles/edges.dir/main.cpp.o: In function `boost::gil::detail::jpeg_reader::~jpeg_reader()':
/usr/include/boost/gil/extension/io/jpeg_io_private.hpp:98: undefined reference to `jpeg_destroy_decompress'
CMakeFiles/edges.dir/main.cpp.o: In function `void boost::gil::detail::jpeg_reader::apply<boost::gil::image_view<boost::gil::memory_based_2d_locator<boost::gil::memory_based_step_iterator<boost::gil::pixel<unsigned char, boost::gil::layout<boost::mpl::vector1<boost::gil::gray_color_t>, boost::mpl::range_c<int, 0, 1> > >*> > > >(boost::gil::image_view<boost::gil::memory_based_2d_locator<boost::gil::memory_based_step_iterator<boost::gil::pixel<unsigned char, boost::gil::layout<boost::mpl::vector1<boost::gil::gray_color_t>, boost::mpl::range_c<int, 0, 1> > >*> > > const&)':
/usr/include/boost/gil/extension/io/jpeg_io_private.hpp:102: undefined reference to `jpeg_start_decompress'
/usr/include/boost/gil/extension/io/jpeg_io_private.hpp:111: undefined reference to `jpeg_read_scanlines'
/usr/include/boost/gil/extension/io/jpeg_io_private.hpp:115: undefined reference to `jpeg_finish_decompress'
CMakeFiles/edges.dir/main.cpp.o: In function `void boost::gil::detail::jpeg_reader::apply<boost::gil::image_view<boost::gil::memory_based_2d_locator<boost::gil::memory_based_step_iterator<boost::gil::pixel<unsigned char, boost::gil::layout<boost::mpl::vector3<boost::gil::red_t, boost::gil::green_t, boost::gil::blue_t>, boost::mpl::range_c<int, 0, 3> > >*> > > >(boost::gil::image_view<boost::gil::memory_based_2d_locator<boost::gil::memory_based_step_iterator<boost::gil::pixel<unsigned char, boost::gil::layout<boost::mpl::vector3<boost::gil::red_t, boost::gil::green_t, boost::gil::blue_t>, boost::mpl::range_c<int, 0, 3> > >*> > > const&)':
/usr/include/boost/gil/extension/io/jpeg_io_private.hpp:102: undefined reference to `jpeg_start_decompress'
/usr/include/boost/gil/extension/io/jpeg_io_private.hpp:111: undefined reference to `jpeg_read_scanlines'
/usr/include/boost/gil/extension/io/jpeg_io_private.hpp:115: undefined reference to `jpeg_finish_decompress'
jpeg 仍然存在问题,但包括来自 extension/io 的所有三个文件不起作用:(
您缺少包含
#include <boost/gil/extension/io/dynamic_io.hpp>
#include <boost/gil/extension/io/jpeg_dynamic_io.hpp>
然后编译链接:
g++ -Wall -Wextra -pedantic -pthread -o sotest test.cpp -ljpeg
@sehe 提供的答案对于 Boost 1.67 或更早版本中发布的 GIL 是完全正确的。
由于 I/O 扩展已在 Boost 1.68 中完全重写 Boost.GIL,您的示例将需要调整。这里更新了,最小版本:
#include <boost/gil.hpp>
#include <boost/gil/extension/dynamic_image/any_image.hpp>
#include <boost/gil/extension/io/jpeg.hpp>
#include <boost/mpl/vector.hpp>
int main()
{
namespace bg = boost::gil;
using my_img_types = boost::mpl::vector<bg::gray8_image_t, bg::gray16_image_t, bg::rgb8_image_t, bg::rgb16_image_t>;
bg::any_image<my_img_types> runtime_image;
bg::read_image("file.jpg", runtime_image, bg::jpeg_tag());
}
可能还值得注意的是,最新的 Boost.GIL 现在需要兼容 C++11 的编译器。
更新:Boost 1.72 提供了从 Boost.MPL 移植到 Boost.MP11 的 GIL,参见 release notes,因此应该使用 mp_list
而不是 mpl::vector
。
我想编写简单的程序来使用 boost::gil 读取和编辑图像。读取图像功能总是出错。我继续在 boost 站点上找到的教程。
#include <iostream>
#include <boost/gil/gil_all.hpp>
#include <boost/gil/extension/io/jpeg_io.hpp>
#include <boost/gil/extension/dynamic_image/any_image.hpp>
#include <boost/gil/channel.hpp>
#include <boost/mpl/vector.hpp>
int main(int argc, char *argv[])
{
namespace bg = boost::gil;
static const std::string resources_dir = "../resources";
static const std::string filename = "face.jpg";
typedef boost::mpl::vector<bg::gray8_image_t, bg::gray16_image_t, bg::rgb8_image_t, bg::rgb16_image_t> my_img_types;
bg::any_image<my_img_types> runtime_image;
try{
bg::jpeg_read_image(resources_dir + filename, runtime_image);
} catch (const std::ios_base::failure &e) {
std::cout << e.what() << std::endl;
}
return 0;
}
错误很长,不知道哪里出了问题。似乎将不受支持的图像类型传递到图像模板中,但无论参数如何,它都会显示 - 我也尝试传递一种类型。
[ 50%] Building CXX object src/CMakeFiles/edges.dir/main.cpp.o
In file included from /usr/include/boost/config.hpp:57:0,
from /usr/include/boost/gil/gil_config.hpp:24,
from /usr/include/boost/gil/gil_all.hpp:25,
from /home/mateusz/projects/edges1/src/main.cpp:2:
/usr/include/boost/gil/extension/io/jpeg_io.hpp: In instantiation of ‘const bool boost::gil::jpeg_read_support<boost::gil::any_image_view<boost::mpl::v_item<boost::gil::image_view<boost::gil::memory_based_2d_locator<boost::gil::memory_based_step_iterator<boost::gil::pixel<short unsigned int, boost::gil::layout<boost::mpl::vector3<boost::gil::red_t, boost::gil::green_t, boost::gil::blue_t> > >*> > >, boost::mpl::v_item<boost::gil::image_view<boost::gil::memory_based_2d_locator<boost::gil::memory_based_step_iterator<boost::gil::pixel<unsigned char, boost::gil::layout<boost::mpl::vector3<boost::gil::red_t, boost::gil::green_t, boost::gil::blue_t> > >*> > >, boost::mpl::v_item<boost::gil::image_view<boost::gil::memory_based_2d_locator<boost::gil::memory_based_step_iterator<boost::gil::pixel<short unsigned int, boost::gil::layout<boost::mpl::vector1<boost::gil::gray_color_t> > >*> > >, boost::mpl::v_item<boost::gil::image_view<boost::gil::memory_based_2d_locator<boost::gil::memory_based_step_iterator<boost::gil::pixel<unsigned char, boost::gil::layout<boost::mpl::vector1<boost::gil::gray_color_t> > >*> > >, boost::mpl::vector0<mpl_::na>, 0>, 0>, 0>, 0> > >::is_supported’:
/usr/include/boost/gil/extension/io/jpeg_io.hpp:91:5: required from ‘void boost::gil::jpeg_read_image(const char*, Image&) [with Image = boost::gil::any_image<boost::mpl::vector<boost::gil::image<boost::gil::pixel<unsigned char, boost::gil::layout<boost::mpl::vector1<boost::gil::gray_color_t> > >, false, std::allocator<unsigned char> >, boost::gil::image<boost::gil::pixel<short unsigned int, boost::gil::layout<boost::mpl::vector1<boost::gil::gray_color_t> > >, false, std::allocator<unsigned char> >, boost::gil::image<boost::gil::pixel<unsigned char, boost::gil::layout<boost::mpl::vector3<boost::gil::red_t, boost::gil::green_t, boost::gil::blue_t> > >, false, std::allocator<unsigned char> >, boost::gil::image<boost::gil::pixel<short unsigned int, boost::gil::layout<boost::mpl::vector3<boost::gil::red_t, boost::gil::green_t, boost::gil::blue_t> > >, false, std::allocator<unsigned char> > > >]’
/usr/include/boost/gil/extension/io/jpeg_io.hpp:101:40: required from ‘void boost::gil::jpeg_read_image(const string&, Image&) [with Image = boost::gil::any_image<boost::mpl::vector<boost::gil::image<boost::gil::pixel<unsigned char, boost::gil::layout<boost::mpl::vector1<boost::gil::gray_color_t> > >, false, std::allocator<unsigned char> >, boost::gil::image<boost::gil::pixel<short unsigned int, boost::gil::layout<boost::mpl::vector1<boost::gil::gray_color_t> > >, false, std::allocator<unsigned char> >, boost::gil::image<boost::gil::pixel<unsigned char, boost::gil::layout<boost::mpl::vector3<boost::gil::red_t, boost::gil::green_t, boost::gil::blue_t> > >, false, std::allocator<unsigned char> >, boost::gil::image<boost::gil::pixel<short unsigned int, boost::gil::layout<boost::mpl::vector3<boost::gil::red_t, boost::gil::green_t, boost::gil::blue_t> > >, false, std::allocator<unsigned char> > > >; std::string = std::basic_string<char>]’
/home/mateusz/projects/edges1/src/main.cpp:18:64: required from here
/usr/include/boost/gil/extension/io/jpeg_io.hpp:40:5: error: invalid use of incomplete type ‘struct boost::gil::channel_type<boost::gil::any_image_view<boost::mpl::v_item<boost::gil::image_view<boost::gil::memory_based_2d_locator<boost::gil::memory_based_step_iterator<boost::gil::pixel<short unsigned int, boost::gil::layout<boost::mpl::vector3<boost::gil::red_t, boost::gil::green_t, boost::gil::blue_t> > >*> > >, boost::mpl::v_item<boost::gil::image_view<boost::gil::memory_based_2d_locator<boost::gil::memory_based_step_iterator<boost::gil::pixel<unsigned char, boost::gil::layout<boost::mpl::vector3<boost::gil::red_t, boost::gil::green_t, boost::gil::blue_t> > >*> > >, boost::mpl::v_item<boost::gil::image_view<boost::gil::memory_based_2d_locator<boost::gil::memory_based_step_iterator<boost::gil::pixel<short unsigned int, boost::gil::layout<boost::mpl::vector1<boost::gil::gray_color_t> > >*> > >, boost::mpl::v_item<boost::gil::image_view<boost::gil::memory_based_2d_locator<boost::gil::memory_based_step_iterator<boost::gil::pixel<unsigned char, boost::gil::layout<boost::mpl::vector1<boost::gil::gray_color_t> > >*> > >, boost::mpl::vector0<mpl_::na>, 0>, 0>, 0>, 0> > >’
BOOST_STATIC_CONSTANT(bool,is_supported=
^
In file included from /usr/include/boost/gil/algorithm.hpp:25:0,
from /usr/include/boost/gil/gil_all.hpp:27,
from /home/mateusz/projects/edges1/src/main.cpp:2:
/usr/include/boost/gil/gil_concept.hpp:49:30: error: declaration of ‘struct boost::gil::channel_type<boost::gil::any_image_view<boost::mpl::v_item<boost::gil::image_view<boost::gil::memory_based_2d_locator<boost::gil::memory_based_step_iterator<boost::gil::pixel<short unsigned int, boost::gil::layout<boost::mpl::vector3<boost::gil::red_t, boost::gil::green_t, boost::gil::blue_t> > >*> > >, boost::mpl::v_item<boost::gil::image_view<boost::gil::memory_based_2d_locator<boost::gil::memory_based_step_iterator<boost::gil::pixel<unsigned char, boost::gil::layout<boost::mpl::vector3<boost::gil::red_t, boost::gil::green_t, boost::gil::blue_t> > >*> > >, boost::mpl::v_item<boost::gil::image_view<boost::gil::memory_based_2d_locator<boost::gil::memory_based_step_iterator<boost::gil::pixel<short unsigned int, boost::gil::layout<boost::mpl::vector1<boost::gil::gray_color_t> > >*> > >, boost::mpl::v_item<boost::gil::image_view<boost::gil::memory_based_2d_locator<boost::gil::memory_based_step_iterator<boost::gil::pixel<unsigned char, boost::gil::layout<boost::mpl::vector1<boost::gil::gray_color_t> > >*> > >, boost::mpl::vector0<mpl_::na>, 0>, 0>, 0>, 0> > >’
template <typename T> struct channel_type;
我也是新手 CMakeLists.txt,所以我包含了这些文件。主文件夹中的 CMakeLists:
cmake_minimum_required(VERSION 2.8)
project(edges1)
set(CMAKE_BUILD_TYPE "Debug")
add_subdirectory(src)
set(EXECUTABLE_OUTPUT_PATH ${PROJECT_BINARY_DIR})
set(LIBRARY_OUTPUT_PATH ${PROJECT_BINARY_DIR})
CMakeLists.txt 在 src 文件夹中:
set(SOURCES main.cpp)
set(EXECUTABLE_OUTPUT_PATH ${PROJECT_BINARY_DIR})
set(LIBRARY_OUTPUT_PATH ${PROJECT_BINARY_DIR})
include_directories(${CMAKE_SOURCE_DIR}/include)
find_package(Boost REQUIRED COMPONENTS)
include_directories(${BOOST_INCLUDE_DIRS})
#link_directoires(${CMAKE_SOURCE_ROOT}/lib)
#link_directoires(${LIBRARY_OUTPUT_PATH})
add_executable(edges ${SOURCES})
使用 read_and_convert_image 给出其他错误...
编辑:
已在 src 目录中安装 libjpeg、CMakeLists:
set(SOURCES main.cpp)
set(EXECUTABLE_OUTPUT_PATH ${PROJECT_BINARY_DIR})
set(LIBRARY_OUTPUT_PATH ${PROJECT_BINARY_DIR})
include_directories(${CMAKE_SOURCE_DIR}/include)
add_executable(edges ${SOURCES})
find_package(Boost REQUIRED COMPONENTS)
IF(BOOST_FOUND)
target_link_libraries(edges Boost::boost)
ENDIF()
find_package(JPEG REQUIRED)
IF(JPEG_FOUND)
include_directories(${JPEG_INCLUDE_DIR})
target_link_libraries(edges ${JPEG_INCLUDE_DIR})
ENDIF()
cmake 命令:
cmake -DJPEG_LIBRARY:PATH=/usr/lib/x86_64-linux-gnu/libjpeg.so --libdir=/usr/lib64 ..
制作后:
[ 50%] Linking CXX executable ../edges
CMakeFiles/edges.dir/main.cpp.o: In function `boost::gil::detail::jpeg_reader::init()':
/usr/include/boost/gil/extension/io/jpeg_io_private.hpp:89: undefined reference to `jpeg_std_error'
/usr/include/boost/gil/extension/io/jpeg_io_private.hpp:90: undefined reference to `jpeg_CreateDecompress'
/usr/include/boost/gil/extension/io/jpeg_io_private.hpp:91: undefined reference to `jpeg_stdio_src'
/usr/include/boost/gil/extension/io/jpeg_io_private.hpp:92: undefined reference to `jpeg_read_header'
CMakeFiles/edges.dir/main.cpp.o: In function `boost::gil::detail::jpeg_reader::~jpeg_reader()':
/usr/include/boost/gil/extension/io/jpeg_io_private.hpp:98: undefined reference to `jpeg_destroy_decompress'
CMakeFiles/edges.dir/main.cpp.o: In function `void boost::gil::detail::jpeg_reader::apply<boost::gil::image_view<boost::gil::memory_based_2d_locator<boost::gil::memory_based_step_iterator<boost::gil::pixel<unsigned char, boost::gil::layout<boost::mpl::vector1<boost::gil::gray_color_t>, boost::mpl::range_c<int, 0, 1> > >*> > > >(boost::gil::image_view<boost::gil::memory_based_2d_locator<boost::gil::memory_based_step_iterator<boost::gil::pixel<unsigned char, boost::gil::layout<boost::mpl::vector1<boost::gil::gray_color_t>, boost::mpl::range_c<int, 0, 1> > >*> > > const&)':
/usr/include/boost/gil/extension/io/jpeg_io_private.hpp:102: undefined reference to `jpeg_start_decompress'
/usr/include/boost/gil/extension/io/jpeg_io_private.hpp:111: undefined reference to `jpeg_read_scanlines'
/usr/include/boost/gil/extension/io/jpeg_io_private.hpp:115: undefined reference to `jpeg_finish_decompress'
CMakeFiles/edges.dir/main.cpp.o: In function `void boost::gil::detail::jpeg_reader::apply<boost::gil::image_view<boost::gil::memory_based_2d_locator<boost::gil::memory_based_step_iterator<boost::gil::pixel<unsigned char, boost::gil::layout<boost::mpl::vector3<boost::gil::red_t, boost::gil::green_t, boost::gil::blue_t>, boost::mpl::range_c<int, 0, 3> > >*> > > >(boost::gil::image_view<boost::gil::memory_based_2d_locator<boost::gil::memory_based_step_iterator<boost::gil::pixel<unsigned char, boost::gil::layout<boost::mpl::vector3<boost::gil::red_t, boost::gil::green_t, boost::gil::blue_t>, boost::mpl::range_c<int, 0, 3> > >*> > > const&)':
/usr/include/boost/gil/extension/io/jpeg_io_private.hpp:102: undefined reference to `jpeg_start_decompress'
/usr/include/boost/gil/extension/io/jpeg_io_private.hpp:111: undefined reference to `jpeg_read_scanlines'
/usr/include/boost/gil/extension/io/jpeg_io_private.hpp:115: undefined reference to `jpeg_finish_decompress'
jpeg 仍然存在问题,但包括来自 extension/io 的所有三个文件不起作用:(
您缺少包含
#include <boost/gil/extension/io/dynamic_io.hpp>
#include <boost/gil/extension/io/jpeg_dynamic_io.hpp>
然后编译链接:
g++ -Wall -Wextra -pedantic -pthread -o sotest test.cpp -ljpeg
@sehe 提供的答案对于 Boost 1.67 或更早版本中发布的 GIL 是完全正确的。
由于 I/O 扩展已在 Boost 1.68 中完全重写 Boost.GIL,您的示例将需要调整。这里更新了,最小版本:
#include <boost/gil.hpp>
#include <boost/gil/extension/dynamic_image/any_image.hpp>
#include <boost/gil/extension/io/jpeg.hpp>
#include <boost/mpl/vector.hpp>
int main()
{
namespace bg = boost::gil;
using my_img_types = boost::mpl::vector<bg::gray8_image_t, bg::gray16_image_t, bg::rgb8_image_t, bg::rgb16_image_t>;
bg::any_image<my_img_types> runtime_image;
bg::read_image("file.jpg", runtime_image, bg::jpeg_tag());
}
可能还值得注意的是,最新的 Boost.GIL 现在需要兼容 C++11 的编译器。
更新:Boost 1.72 提供了从 Boost.MPL 移植到 Boost.MP11 的 GIL,参见 release notes,因此应该使用 mp_list
而不是 mpl::vector
。