From eee0d295c3825ed2071e5247974417b2ae09a045 Mon Sep 17 00:00:00 2001 From: Davis King Date: Sun, 17 Jan 2016 12:06:53 -0500 Subject: [PATCH] Improved error message you get about linking to libjpeg and libpng if you try to open a jpeg or png file. --- dlib/image_loader/load_image.h | 35 ++++++++++++++++++++++++++++------ 1 file changed, 29 insertions(+), 6 deletions(-) diff --git a/dlib/image_loader/load_image.h b/dlib/image_loader/load_image.h index da311ab95..b97836f65 100644 --- a/dlib/image_loader/load_image.h +++ b/dlib/image_loader/load_image.h @@ -9,6 +9,7 @@ #include "jpeg_loader.h" #include "image_loader.h" #include +#include namespace dlib { @@ -71,15 +72,37 @@ namespace dlib if (im_type == image_file_type::JPG) { - throw image_load_error("Unable to load image in file " + file_name + ".\n" + - "You must #define DLIB_JPEG_SUPPORT and link to libjpeg to read JPEG files.\n" + - "Do this by following the instructions at http://dlib.net/compile.html."); + std::ostringstream sout; + sout << "Unable to load image in file " + file_name + ".\n" + + "You must #define DLIB_JPEG_SUPPORT and link to libjpeg to read JPEG files.\n" + + "Do this by following the instructions at http://dlib.net/compile.html.\n\n"; +#ifdef _MSC_VER + sout << "Note that you must cause DLIB_JPEG_SUPPORT to be defined for your entire project.\n"; + sout << "So don't #define it in one file, add it to the C/C++->Preprocessor->Preprocessor Definitions\n"; + sout << "field in Visual Studio's Property Pages window so it takes effect for your entire application."; +#else + sout << "Note that you must cause DLIB_JPEG_SUPPORT to be defined for your entire project.\n"; + sout << "So don't #define it in one file, use a compiler switch like -DDLIB_JPEG_SUPPORT\n"; + sout << "so it takes effect for your entire application."; +#endif + throw image_load_error(sout.str()); } else if (im_type == image_file_type::PNG) { - throw image_load_error("Unable to load image in file " + file_name + ".\n" + - "You must #define DLIB_PNG_SUPPORT and link to libpng to read PNG files.\n" + - "Do this by following the instructions at http://dlib.net/compile.html."); + std::ostringstream sout; + sout << "Unable to load image in file " + file_name + ".\n" + + "You must #define DLIB_PNG_SUPPORT and link to libpng to read PNG files.\n" + + "Do this by following the instructions at http://dlib.net/compile.html.\n\n"; +#ifdef _MSC_VER + sout << "Note that you must cause DLIB_PNG_SUPPORT to be defined for your entire project.\n"; + sout << "So don't #define it in one file, add it to the C/C++->Preprocessor->Preprocessor Definitions\n"; + sout << "field in Visual Studio's Property Pages window so it takes effect for your entire application.\n"; +#else + sout << "Note that you must cause DLIB_PNG_SUPPORT to be defined for your entire project.\n"; + sout << "So don't #define it in one file, use a compiler switch like -DDLIB_PNG_SUPPORT\n"; + sout << "so it takes effect for your entire application."; +#endif + throw image_load_error(sout.str()); } else {