diff --git a/dlib/CMakeLists.txt b/dlib/CMakeLists.txt index 9a6a60a2b..ed094288a 100644 --- a/dlib/CMakeLists.txt +++ b/dlib/CMakeLists.txt @@ -283,7 +283,7 @@ if (NOT TARGET dlib) set (dlib_needed_libraries ${dlib_needed_libraries} ${JPEG_LIBRARY}) else() # If we can't find libjpeg then statically compile it in. - include_directories(external/libjpeg) + add_definitions(-DDLIB_JPEG_STATIC) set(source_files ${source_files} external/libjpeg/jcomapi.cpp external/libjpeg/jdapimin.cpp diff --git a/dlib/external/libjpeg/jmorecfg.h b/dlib/external/libjpeg/jmorecfg.h index 66e37f296..6082f069a 100644 --- a/dlib/external/libjpeg/jmorecfg.h +++ b/dlib/external/libjpeg/jmorecfg.h @@ -171,8 +171,13 @@ typedef unsigned int JDIMENSION; #define LOCAL(type) static type /* a function referenced thru EXTERNs: */ #define GLOBAL(type) type -/* a reference to a GLOBAL function: */ -#ifdef __cplusplus +/* + Use C linking unless we are supposed to be compiling our own copy of + libjpeg. Then let it use C++ linking so that we are less likely to get + linker name conflicts with other libraries that happen to statically include + libjpeg as well. +*/ +#if defined(__cplusplus) && !defined(DLIB_JPEG_STATIC) #define EXTERN(type) extern "C" type #else #define EXTERN(type) extern type diff --git a/dlib/image_loader/jpeg_loader.cpp b/dlib/image_loader/jpeg_loader.cpp index e3aa998b7..83ad18ee5 100644 --- a/dlib/image_loader/jpeg_loader.cpp +++ b/dlib/image_loader/jpeg_loader.cpp @@ -11,7 +11,11 @@ #include "../dir_nav.h" #include "jpeg_loader.h" #include -#include +#ifdef DLIB_JPEG_STATIC +# include "../external/libjpeg/jpeglib.h" +#else +# include +#endif #include #include diff --git a/dlib/image_saver/save_jpeg.cpp b/dlib/image_saver/save_jpeg.cpp index 17eb028df..9fc816e4b 100644 --- a/dlib/image_saver/save_jpeg.cpp +++ b/dlib/image_saver/save_jpeg.cpp @@ -10,7 +10,11 @@ #include "../pixel.h" #include "save_jpeg.h" #include -#include +#ifdef DLIB_JPEG_STATIC +# include "../external/libjpeg/jpeglib.h" +#else +# include +#endif #include #include #include "image_saver.h"