Commit 34b0a2e1 authored by Davis King's avatar Davis King

Added a link time check that you aren't mixing headers from one version of dlib

with binaries from a different dlib version.
parent e8117679
......@@ -744,6 +744,13 @@ if (NOT TARGET dlib)
# the code in dlib/threads_kernel_shared.cpp to emit a linker error for users who
# don't use the configured config.h file generated by cmake.
target_compile_options(dlib PRIVATE -DDLIB__CMAKE_GENERATED_A_CONFIG_H_FILE)
# Do this so that dlib/config.h can record the version of dlib it's configured with
# and ultimately issue a linker error to people who try to use a binary dlib that is
# the wrong version.
set(DLIB_CHECK_FOR_VERSION_MISSMATCH
DLIB_VERSION_CHECK_${CPACK_PACKAGE_VERSION_MAJOR}_${CPACK_PACKAGE_VERSION_MINOR}_${CPACK_PACKAGE_VERSION_PATCH})
target_compile_options(dlib PRIVATE "-DDLIB_CHECK_FOR_VERSION_MISSMATCH=${DLIB_CHECK_FOR_VERSION_MISSMATCH}")
endif()
......
......@@ -27,3 +27,8 @@
#cmakedefine DLIB_USE_LAPACK
#cmakedefine DLIB_USE_CUDA
#cmakedefine DLIB_USE_MKL_FFT
// This variable allows dlib/test_for_odr_violations.h to catch people who mistakenly use
// headers from one version of dlib with a compiled dlib binary from a different dlib version.
#cmakedefine DLIB_CHECK_FOR_VERSION_MISSMATCH @DLIB_CHECK_FOR_VERSION_MISSMATCH@
......@@ -31,6 +31,15 @@ extern "C"
#if defined(DLIB_NOT_CONFIGURED) && !defined(DLIB__CMAKE_GENERATED_A_CONFIG_H_FILE)
int USER_ERROR__inconsistent_build_configuration__see_dlib_faq_2;
#endif
#ifdef DLIB_CHECK_FOR_VERSION_MISSMATCH
int DLIB_CHECK_FOR_VERSION_MISSMATCH;
#endif
}
......
......@@ -41,15 +41,20 @@ extern "C"
#if defined(DLIB_NOT_CONFIGURED) && !defined(DLIB__CMAKE_GENERATED_A_CONFIG_H_FILE)
extern int USER_ERROR__inconsistent_build_configuration__see_dlib_faq_2;
inline int dlib_check_consistent_config_h_usage() { USER_ERROR__inconsistent_build_configuration__see_dlib_faq_2 = 0; return 0; }
#else
inline int dlib_check_consistent_config_h_usage() { return 0; }
#endif
const int DLIB_NO_WARN_UNUSED dlib_check_not_configured_helper_variable = dlib_check_consistent_config_h_usage();
#endif
}
// Cause the user to get a linker error if they try to use header files from one version of
// dlib with the compiled binary from a different version of dlib.
#ifdef DLIB_CHECK_FOR_VERSION_MISSMATCH
extern int DLIB_CHECK_FOR_VERSION_MISSMATCH;
inline int dlib_check_for_dlib_version_missmatch() { DLIB_CHECK_FOR_VERSION_MISSMATCH = 0; return 0; }
const int DLIB_NO_WARN_UNUSED dlib_check_for_version_missmatch = dlib_check_for_dlib_version_missmatch();
#endif
}
#endif // DLIB_TEST_FOR_ODR_VIOLATIONS_H_
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment