Opencv learning notes (26) automatically recognize opencv versions and add dependent Libraries

Source: Internet
Author: User
Tags wxwidgets

From http://blog.csdn.net/chenyusiyuan/article/details/8706177

 

Here we will introduce a method to automatically identify the opencv version number in the header file and add the corresponding dependent Library (. Lib file) accordingly. DetailsCodeAs follows:

 # Ifndef _ predep_h _  # Define _ Predep_h _ # Pragma Once # Include  "  Targetver. h  "  # Include <Stdio. h> # Include <Tchar. h> # Include <Iostream>
# Include " Opencv2/CORE/version. HPP " # Include " Opencv2/imgproc. HPP " # Include " Opencv2/highgui. HPP " # Include " Opencv2/calib3d/calib3d. HPP " # Define Cv_version_id cvaux_str (cv_major_version) cvaux_str (cv_minor_version) cvaux_str (cv_subminor_version) # Ifdef _ debug # Define Cvlib (name) "opencv _" name cv_version_id "D" # Else # Define Cvlib (name) "opencv _" name cv_version_id # Endif # Pragma Comment (Lib, cvlib ("core ")) # Pragma Comment (Lib, cvlib ("imgproc ")) # Pragma Comment (Lib, cvlib ("highgui ")) # Pragma Comment (Lib, cvlib ("FLANN ")) # Pragma Comment (Lib, cvlib ("features2d ")) # Pragma Comment (Lib, cvlib ("calib3d ")) # Endif

First, obtain the version number through the version. HPP file of opencv, and then concatenate the numbers cv_major_version, cv_minor_version, and cv_subminor_version into a string cv_version_id. Then, define a macro cvlib named lib File Based on the naming rules of the Lib file of opencv and the current compiling environment (debug or release. Finally, use the # pragma comment (Lib, *) command to add the required dependent libraries.

The convenience of the above method is that we only need to specify the name of the dependent Library, through the defined macro can automatically generate and add the dependent library corresponding to the installed opencv version; in addition, when you upgrade opencv in the future, you do not need to change the code unless the new version of the dependent database naming rules change,ProgramIt will automatically determine the opencv version and find the corresponding dependent library.

This method is based on wxWidgets. For more techniques, see wxWidgets \ include \ msvc \ wx \ setup. h and wxWidgets \ include \ wx \ version. h.

p.s.: In addition, it is recommended to set a special item in the system environment variable to store the installation path of opencv, for example, name it opencvdir, then, in the Visual Studio project property VC ++ directory, set the include directory and library directory to $ (opencvdir)/include and $ (opencvdir)/lib. In this way, when you upgrade opencv later, you only need to modify the opencvdir path in the system environment variable, and you do not need to modify the project code and compiler settings.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.