Skip to content

Instantly share code, notes, and snippets.

@kazuki-ma
Created June 25, 2012 11:00
Show Gist options
  • Save kazuki-ma/2987957 to your computer and use it in GitHub Desktop.
Save kazuki-ma/2987957 to your computer and use it in GitHub Desktop.
OpenCV auto library linking for Visual Studio / OpenCV 2.4.1
Index: modules/calib3d/include/opencv2/calib3d/calib3d.hpp
===================================================================
--- modules/calib3d/include/opencv2/calib3d/calib3d.hpp (revision 8696)
+++ modules/calib3d/include/opencv2/calib3d/calib3d.hpp (working copy)
@@ -748,4 +748,10 @@
#endif
+// Auto linking by "#pragma comment(lib)" syntax
+#include "opencv2/core/pragma_lib.hpp"
+#if PRAGMA_COMMENT_SUPPORT && OPENCV_AUTO_LINK
+#pragma OPENCV_COMMENT_LIB_FNAME("calib3d")
+#endif // PRAGMA_COMMENT_SUPPORT && OPENCV_AUTO_LINK
+
#endif
Index: modules/contrib/include/opencv2/contrib/contrib.hpp
===================================================================
--- modules/contrib/include/opencv2/contrib/contrib.hpp (revision 8696)
+++ modules/contrib/include/opencv2/contrib/contrib.hpp (working copy)
@@ -979,5 +979,10 @@
#endif
-#endif
+// Auto linking by "#pragma comment(lib)" syntax
+#include "opencv2/core/pragma_lib.hpp"
+#if PRAGMA_COMMENT_SUPPORT && OPENCV_AUTO_LINK
+#pragma OPENCV_COMMENT_LIB_FNAME("contrib")
+#endif // PRAGMA_COMMENT_SUPPORT && OPENCV_AUTO_LINK
+#endif
\ No newline at end of file
Index: modules/contrib/src/retinacolor.cpp
===================================================================
--- modules/contrib/src/retinacolor.cpp (revision 8696)
+++ modules/contrib/src/retinacolor.cpp (working copy)
@@ -1,4 +1,4 @@
-/*#******************************************************************************
+/*#******************************************************************************
** IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING.
**
** By downloading, copying, installing or using the software you agree to this license.
Index: modules/contrib/src/retinafilter.hpp
===================================================================
--- modules/contrib/src/retinafilter.hpp (revision 8696)
+++ modules/contrib/src/retinafilter.hpp (working copy)
@@ -1,4 +1,4 @@
-/*#******************************************************************************
+/*#******************************************************************************
** IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING.
**
** By downloading, copying, installing or using the software you agree to this license.
Index: modules/core/include/opencv2/core/core.hpp
===================================================================
--- modules/core/include/opencv2/core/core.hpp (revision 8696)
+++ modules/core/include/opencv2/core/core.hpp (working copy)
@@ -4587,4 +4587,10 @@
#include "opencv2/core/operations.hpp"
#include "opencv2/core/mat.hpp"
+// Auto linking by "#pragma comment(lib)" syntax
+#include "opencv2/core/pragma_lib.hpp"
+#if PRAGMA_COMMENT_SUPPORT && OPENCV_AUTO_LINK
+#pragma OPENCV_COMMENT_LIB_FNAME("core")
+#endif
+
#endif /*__OPENCV_CORE_HPP__*/
Index: modules/core/include/opencv2/core/pragma_lib.hpp
===================================================================
--- modules/core/include/opencv2/core/pragma_lib.hpp (revision 0)
+++ modules/core/include/opencv2/core/pragma_lib.hpp (working copy)
@@ -0,0 +1,91 @@
+/*! \file pragma_include.hpp
+ \brief #pragmas for auto library linking
+ */
+/*M///////////////////////////////////////////////////////////////////////////////////////
+//
+// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING.
+//
+// By downloading, copying, installing or using the software you agree to this license.
+// If you do not agree to this license, do not download, install,
+// copy or use the software.
+//
+//
+// License Agreement
+// For Open Source Computer Vision Library
+//
+// Copyright (C) 2000-2008, Intel Corporation, all rights reserved.
+// Copyright (C) 2009-2011, Willow Garage Inc., all rights reserved.
+// Third party copyrights are property of their respective owners.
+//
+// Redistribution and use in source and binary forms, with or without modification,
+// are permitted provided that the following conditions are met:
+//
+// * Redistribution's of source code must retain the above copyright notice,
+// this list of conditions and the following disclaimer.
+//
+// * Redistribution's in binary form must reproduce the above copyright notice,
+// this list of conditions and the following disclaimer in the documentation
+// and/or other materials provided with the distribution.
+//
+// * The name of the copyright holders may not be used to endorse or promote products
+// derived from this software without specific prior written permission.
+//
+// This software is provided by the copyright holders and contributors "as is" and
+// any express or implied warranties, including, but not limited to, the implied
+// warranties of merchantability and fitness for a particular purpose are disclaimed.
+// In no event shall the Intel Corporation or contributors be liable for any direct,
+// indirect, incidental, special, exemplary, or consequential damages
+// (including, but not limited to, procurement of substitute goods or services;
+// loss of use, data, or profits; or business interruption) however caused
+// and on any theory of liability, whether in contract, strict liability,
+// or tort (including negligence or otherwise) arising in any way out of
+// the use of this software, even if advised of the possibility of such damage.
+//
+//M*/
+
+#ifndef __OPENCV_PRAGMA_LIB_HPP__
+#define __OPENCV_PRAGMA_LIB_HPP__ 1
+
+#if (defined(_MSC_VER) && !defined(PRAGMA_COMMENT_SUPPORT)) \
+ && !defined(CVAPI_EXPORTS)
+#define PRAGMA_COMMENT_SUPPORT 1
+#elif !defined(PRAGMA_COMMENT_SUPPORT)
+#define PRAGMA_COMMENT_SUPPORT 0
+#endif
+
+#ifndef CV_MAJOR_VERSION
+#pragma message("WARM: Any OpenCV header included before pragma_lib.hpp")
+#include "opencv2/core/version.hpp"
+#endif
+
+// version string which contains in library's file name such as "232"
+#define OPENCV_LIBVERSTR \
+ CVAUX_STR(CV_MAJOR_VERSION) \
+ CVAUX_STR(CV_MINOR_VERSION) \
+ CVAUX_STR(CV_SUBMINOR_VERSION)
+
+// generate #pragma arguments string
+#ifndef _DEBUG // Release
+#define OPENCV_COMMENT_LIB_FNAME(name) \
+comment(lib, "opencv_" name OPENCV_LIBVERSTR ".lib")
+#else // Debug
+#define OPENCV_COMMENT_LIB_FNAME(name) \
+comment(lib, "opencv_" name OPENCV_LIBVERSTR "d.lib")
+#endif
+
+// defined macro search,
+// OPENCV_DEFINE_SEARCH(modulename) is only true
+// when header file of modulename is included.
+#define OPENCV_DEFINE_SEARCH(modulename) \
+ ( \
+ defined( __OPENCV_##modulename##_HPP__ ) || \
+ defined( _OPENCV_##modulename##_HPP_ ) || \
+ defined( __OPENCV_##modulename##_H__ ) || \
+ defined( __OPENCV_##modulename##_##name##_C_H ) \
+ )
+
+#ifndef OPENCV_AUTO_LINK
+#define OPENCV_AUTO_LINK 1
+#endif
+
+#endif // #ifndef __OPENCV_PRAGMA_LIB_HPP__
Index: modules/features2d/include/opencv2/features2d/features2d.hpp
===================================================================
--- modules/features2d/include/opencv2/features2d/features2d.hpp (revision 8696)
+++ modules/features2d/include/opencv2/features2d/features2d.hpp (working copy)
@@ -1410,6 +1410,12 @@
#endif /* __cplusplus */
+// Auto linking by "#pragma comment(lib)" syntax
+#include "opencv2/core/pragma_lib.hpp"
+#if PRAGMA_COMMENT_SUPPORT && OPENCV_AUTO_LINK
+#pragma OPENCV_COMMENT_LIB_FNAME("features2d")
+#endif // PRAGMA_COMMENT_SUPPORT && OPENCV_AUTO_LINK
+
#endif
/* End of file. */
Index: modules/flann/include/opencv2/flann/flann.hpp
===================================================================
--- modules/flann/include/opencv2/flann/flann.hpp (revision 8696)
+++ modules/flann/include/opencv2/flann/flann.hpp (working copy)
@@ -40,8 +40,8 @@
//
//M*/
-#ifndef _OPENCV_FLANN_HPP_
-#define _OPENCV_FLANN_HPP_
+#ifndef __OPENCV_FLANN_HPP__
+#define __OPENCV_FLANN_HPP__
#ifdef __cplusplus
@@ -423,5 +423,11 @@
} } // namespace cv::flann
#endif // __cplusplus
+
+// Auto linking by "#pragma comment(lib)" syntax
+#include "opencv2/core/pragma_lib.hpp"
+#if PRAGMA_COMMENT_SUPPORT && OPENCV_AUTO_LINK
+#pragma OPENCV_COMMENT_LIB_FNAME("flann")
+#endif // PRAGMA_COMMENT_SUPPORT && OPENCV_AUTO_LINK
#endif
Index: modules/gpu/include/opencv2/gpu/gpu.hpp
===================================================================
--- modules/gpu/include/opencv2/gpu/gpu.hpp (revision 8696)
+++ modules/gpu/include/opencv2/gpu/gpu.hpp (working copy)
@@ -1894,4 +1894,10 @@
} // namespace cv
+// Auto linking by "#pragma comment(lib)" syntax
+#include "opencv2/core/pragma_lib.hpp"
+#if PRAGMA_COMMENT_SUPPORT && OPENCV_AUTO_LINK
+#pragma OPENCV_COMMENT_LIB_FNAME("gpu")
+#endif // PRAGMA_COMMENT_SUPPORT && OPENCV_AUTO_LINK
+
#endif /* __OPENCV_GPU_HPP__ */
Index: modules/highgui/include/opencv2/highgui/highgui.hpp
===================================================================
--- modules/highgui/include/opencv2/highgui/highgui.hpp (revision 8696)
+++ modules/highgui/include/opencv2/highgui/highgui.hpp (working copy)
@@ -248,4 +248,10 @@
#endif
+// Auto linking by "#pragma comment(lib)" syntax
+#include "opencv2/core/pragma_lib.hpp"
+#if PRAGMA_COMMENT_SUPPORT && OPENCV_AUTO_LINK
+#pragma OPENCV_COMMENT_LIB_FNAME("highgui")
+#endif // PRAGMA_COMMENT_SUPPORT && OPENCV_AUTO_LINK
+
#endif
Index: modules/imgproc/include/opencv2/imgproc/imgproc.hpp
===================================================================
--- modules/imgproc/include/opencv2/imgproc/imgproc.hpp (revision 8696)
+++ modules/imgproc/include/opencv2/imgproc/imgproc.hpp (working copy)
@@ -1222,6 +1222,12 @@
#endif /* __cplusplus */
+// Auto linking by "#pragma comment(lib)" syntax
+#include "opencv2/core/pragma_lib.hpp"
+#if PRAGMA_COMMENT_SUPPORT && OPENCV_AUTO_LINK
+#pragma OPENCV_COMMENT_LIB_FNAME("imgproc")
+#endif // PRAGMA_COMMENT_SUPPORT && OPENCV_AUTO_LINK
+
#endif
/* End of file. */
Index: modules/imgproc/src/grabcut.cpp
===================================================================
--- modules/imgproc/src/grabcut.cpp (revision 8696)
+++ modules/imgproc/src/grabcut.cpp (working copy)
@@ -1,4 +1,4 @@
-/*M///////////////////////////////////////////////////////////////////////////////////////
+/*M///////////////////////////////////////////////////////////////////////////////////////
//
// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING.
//
Index: modules/legacy/include/opencv2/legacy/compat.hpp
===================================================================
--- modules/legacy/include/opencv2/legacy/compat.hpp (revision 8696)
+++ modules/legacy/include/opencv2/legacy/compat.hpp (working copy)
@@ -1,4 +1,4 @@
-/*M///////////////////////////////////////////////////////////////////////////////////////
+/*M///////////////////////////////////////////////////////////////////////////////////////
//
// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING.
//
Index: modules/legacy/include/opencv2/legacy/legacy.hpp
===================================================================
--- modules/legacy/include/opencv2/legacy/legacy.hpp (revision 8696)
+++ modules/legacy/include/opencv2/legacy/legacy.hpp (working copy)
@@ -3432,6 +3432,12 @@
}
#endif
+// Auto linking by "#pragma comment(lib)" syntax
+#include "opencv2/core/pragma_lib.hpp"
+#if PRAGMA_COMMENT_SUPPORT && OPENCV_AUTO_LINK
+#pragma OPENCV_COMMENT_LIB_FNAME("legacy")
+#endif // PRAGMA_COMMENT_SUPPORT && OPENCV_AUTO_LINK
+
#endif
/* End of file. */
Index: modules/legacy/src/bgfg_estimation.cpp
===================================================================
--- modules/legacy/src/bgfg_estimation.cpp (revision 8696)
+++ modules/legacy/src/bgfg_estimation.cpp (working copy)
@@ -1,4 +1,4 @@
-/*M///////////////////////////////////////////////////////////////////////////////////////
+/*M///////////////////////////////////////////////////////////////////////////////////////
//
// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING.
//
Index: modules/ml/include/opencv2/ml/ml.hpp
===================================================================
--- modules/ml/include/opencv2/ml/ml.hpp (revision 8696)
+++ modules/ml/include/opencv2/ml/ml.hpp (working copy)
@@ -2143,4 +2143,10 @@
#endif // __cplusplus
#endif // __OPENCV_ML_HPP__
+// Auto linking by "#pragma comment(lib)" syntax
+#include "opencv2/core/pragma_lib.hpp"
+#if PRAGMA_COMMENT_SUPPORT && OPENCV_AUTO_LINK
+#pragma OPENCV_COMMENT_LIB_FNAME("ml")
+#endif // PRAGMA_COMMENT_SUPPORT && OPENCV_AUTO_LINK
+
/* End of file. */
Index: modules/nonfree/include/opencv2/nonfree/nonfree.hpp
===================================================================
--- modules/nonfree/include/opencv2/nonfree/nonfree.hpp (revision 8696)
+++ modules/nonfree/include/opencv2/nonfree/nonfree.hpp (working copy)
@@ -52,6 +52,12 @@
}
+// Auto linking by "#pragma comment(lib)" syntax
+#include "opencv2/core/pragma_lib.hpp"
+#if PRAGMA_COMMENT_SUPPORT && OPENCV_AUTO_LINK
+#pragma OPENCV_COMMENT_LIB_FNAME("nonfree")
+#endif // PRAGMA_COMMENT_SUPPORT && OPENCV_AUTO_LINK
+
#endif
/* End of file. */
Index: modules/objdetect/include/opencv2/objdetect/objdetect.hpp
===================================================================
--- modules/objdetect/include/opencv2/objdetect/objdetect.hpp (revision 8696)
+++ modules/objdetect/include/opencv2/objdetect/objdetect.hpp (working copy)
@@ -1021,4 +1021,10 @@
#endif
+// Auto linking by "#pragma comment(lib)" syntax
+#include "opencv2/core/pragma_lib.hpp"
+#if PRAGMA_COMMENT_SUPPORT && OPENCV_AUTO_LINK
+#pragma OPENCV_COMMENT_LIB_FNAME("objdetect")
+#endif // PRAGMA_COMMENT_SUPPORT && OPENCV_AUTO_LINK
+
#endif
Index: modules/photo/include/opencv2/photo/photo.hpp
===================================================================
--- modules/photo/include/opencv2/photo/photo.hpp (revision 8696)
+++ modules/photo/include/opencv2/photo/photo.hpp (working copy)
@@ -71,4 +71,10 @@
#endif
+// Auto linking by "#pragma comment(lib)" syntax
+#include "opencv2/core/pragma_lib.hpp"
+#if PRAGMA_COMMENT_SUPPORT && OPENCV_AUTO_LINK
+#pragma OPENCV_COMMENT_LIB_FNAME("photo")
+#endif // PRAGMA_COMMENT_SUPPORT && OPENCV_AUTO_LINK
+
#endif
Index: modules/stitching/include/opencv2/stitching/stitcher.hpp
===================================================================
--- modules/stitching/include/opencv2/stitching/stitcher.hpp (revision 8696)
+++ modules/stitching/include/opencv2/stitching/stitcher.hpp (working copy)
@@ -167,4 +167,10 @@
} // namespace cv
+// Auto linking by "#pragma comment(lib)" syntax
+#include "opencv2/core/pragma_lib.hpp"
+#if PRAGMA_COMMENT_SUPPORT && OPENCV_AUTO_LINK
+#pragma OPENCV_COMMENT_LIB_FNAME("stitching")
+#endif // PRAGMA_COMMENT_SUPPORT && OPENCV_AUTO_LINK
+
#endif // __OPENCV_STITCHING_STITCHER_HPP__
Index: modules/ts/include/opencv2/ts/ts.hpp
===================================================================
--- modules/ts/include/opencv2/ts/ts.hpp (revision 8696)
+++ modules/ts/include/opencv2/ts/ts.hpp (working copy)
@@ -558,4 +558,10 @@
#endif
+// Auto linking by "#pragma comment(lib)" syntax
+#include "opencv2/core/pragma_lib.hpp"
+#if PRAGMA_COMMENT_SUPPORT && OPENCV_AUTO_LINK
+#pragma OPENCV_COMMENT_LIB_FNAME("ts")
+#endif // PRAGMA_COMMENT_SUPPORT && OPENCV_AUTO_LINK
+
#include "ts_perf.hpp"
Index: modules/video/include/opencv2/video/video.hpp
===================================================================
--- modules/video/include/opencv2/video/video.hpp (revision 8696)
+++ modules/video/include/opencv2/video/video.hpp (working copy)
@@ -1,51 +1,52 @@
-/*M///////////////////////////////////////////////////////////////////////////////////////
-//
-// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING.
-//
-// By downloading, copying, installing or using the software you agree to this license.
-// If you do not agree to this license, do not download, install,
-// copy or use the software.
-//
-//
-// License Agreement
-// For Open Source Computer Vision Library
-//
-// Copyright (C) 2000-2008, Intel Corporation, all rights reserved.
-// Copyright (C) 2009, Willow Garage Inc., all rights reserved.
-// Third party copyrights are property of their respective owners.
-//
-// Redistribution and use in source and binary forms, with or without modification,
-// are permitted provided that the following conditions are met:
-//
-// * Redistribution's of source code must retain the above copyright notice,
-// this list of conditions and the following disclaimer.
-//
-// * Redistribution's in binary form must reproduce the above copyright notice,
-// this list of conditions and the following disclaimer in the documentation
-// and/or other materials provided with the distribution.
-//
-// * The name of the copyright holders may not be used to endorse or promote products
-// derived from this software without specific prior written permission.
-//
-// This software is provided by the copyright holders and contributors "as is" and
-// any express or implied warranties, including, but not limited to, the implied
-// warranties of merchantability and fitness for a particular purpose are disclaimed.
-// In no event shall the Intel Corporation or contributors be liable for any direct,
-// indirect, incidental, special, exemplary, or consequential damages
-// (including, but not limited to, procurement of substitute goods or services;
-// loss of use, data, or profits; or business interruption) however caused
-// and on any theory of liability, whether in contract, strict liability,
-// or tort (including negligence or otherwise) arising in any way out of
-// the use of this software, even if advised of the possibility of such damage.
-//
-//M*/
+/*M///////////////////////////////////////////////////////////////////////////////////////
+//
+// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING.
+//
+// By downloading, copying, installing or using the software you agree to this license.
+// If you do not agree to this license, do not download, install,
+// copy or use the software.
+//
+//
+// License Agreement
+// For Open Source Computer Vision Library
+//
+// Copyright (C) 2000-2008, Intel Corporation, all rights reserved.
+// Copyright (C) 2009, Willow Garage Inc., all rights reserved.
+// Third party copyrights are property of their respective owners.
+//
+// Redistribution and use in source and binary forms, with or without modification,
+// are permitted provided that the following conditions are met:
+//
+// * Redistribution's of source code must retain the above copyright notice,
+// this list of conditions and the following disclaimer.
+//
+// * Redistribution's in binary form must reproduce the above copyright notice,
+// this list of conditions and the following disclaimer in the documentation
+// and/or other materials provided with the distribution.
+//
+// * The name of the copyright holders may not be used to endorse or promote products
+// derived from this software without specific prior written permission.
+//
+// This software is provided by the copyright holders and contributors "as is" and
+// any express or implied warranties, including, but not limited to, the implied
+// warranties of merchantability and fitness for a particular purpose are disclaimed.
+// In no event shall the Intel Corporation or contributors be liable for any direct,
+// indirect, incidental, special, exemplary, or consequential damages
+// (including, but not limited to, procurement of substitute goods or services;
+// loss of use, data, or profits; or business interruption) however caused
+// and on any theory of liability, whether in contract, strict liability,
+// or tort (including negligence or otherwise) arising in any way out of
+// the use of this software, even if advised of the possibility of such damage.
+//
+//M*/
+
+#ifndef __OPENCV_VIDEO_HPP__
+#define __OPENCV_VIDEO_HPP__
+
+#include "opencv2/video/tracking.hpp"
+#include "opencv2/video/background_segm.hpp"
-#ifndef __OPENCV_VIDEO_HPP__
-#define __OPENCV_VIDEO_HPP__
-#include "opencv2/video/tracking.hpp"
-#include "opencv2/video/background_segm.hpp"
-
#ifdef __cplusplus
namespace cv
{
@@ -53,6 +54,9 @@
CV_EXPORTS bool initModule_video(void);
}
-#endif
-
-#endif //__OPENCV_VIDEO_HPP__
+#endif// Auto linking by "#pragma comment(lib)" syntax
+#include "opencv2/core/pragma_lib.hpp"
+#if PRAGMA_COMMENT_SUPPORT && OPENCV_AUTO_LINK
+#pragma OPENCV_COMMENT_LIB_FNAME("video")
+#endif // PRAGMA_COMMENT_SUPPORT && OPENCV_AUTO_LINK
+#endif //__OPENCV_VIDEO_HPP__
Index: modules/videostab/include/opencv2/videostab/videostab.hpp
===================================================================
--- modules/videostab/include/opencv2/videostab/videostab.hpp (revision 8696)
+++ modules/videostab/include/opencv2/videostab/videostab.hpp (working copy)
@@ -45,4 +45,10 @@
#include "opencv2/videostab/stabilizer.hpp"
+// Auto linking by "#pragma comment(lib)" syntax
+#include "opencv2/core/pragma_lib.hpp"
+#if PRAGMA_COMMENT_SUPPORT && OPENCV_AUTO_LINK
+#pragma OPENCV_COMMENT_LIB_FNAME("videostab")
+#endif // PRAGMA_COMMENT_SUPPORT && OPENCV_AUTO_LINK
+
#endif
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment