Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to realize the search path of find_package () in C language

2025-01-19 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/02 Report--

This article introduces how to realize the search path of find_package () in C language. The content is very detailed. Interested friends can use it for reference. I hope it will be helpful to you.

Find_package ()

Change file path and dynamic shared library file implemented internally with find_path () and find_library ()

First of all, to be clear, find_package () must need a .cmake file, otherwise it won't know exactly what the name of package is (uppercase? Lowercase? ), where to find it?

Module mode

(1) whether there is a CMAKE_MODULE_PATH, if so, give priority to looking for the Find.cmake file here, according to this file; (it is easiest to operate by yourself)

Set (CMAKE_MODULE_PATH ${PROJECT_SOURCE_DIR} / cmake_module)

(2) if there is no CMAKE_MODULE_PATH, find (/ usr/share/cmake-3.10-Modules) in cmake Modules

Config mode

To find a Config.cmake or-config.cmake file, look in the order:

(1) _ ROOT variable path, added to cmake3.12

(2) the path of the _ DIR variable. If you have it, you don't need the one above (you can use this to define this variable)

Set (OpenCV_ROOT "/ usr/lib/opencv_249/build") # can be found in the subdirectory # in order to find the .cmake file set (OpenCV_DIR "/ usr/lib/opencv_300/build") # retarded, you can't look up find_package (OpenCV REQUIRED NO_MODULE # tells CMake to use config mode NO_DEFAULT_PATH) # and don't look other anywhere # the .cmake file found in ${OpenCV} at this time

If you don't have a .cmake file and you don't want to write a .cmake file yourself, don't use find_package, just be rude:

# this is how find_package is implemented # header file directory (absolute path to a directory) find_path (NAMES XX.h PATHS / usr/include / usr\ local/include/...) # library file (absolute path to a file) find_library (NAMES lib-name PATHS / usr/lib / usr/local/lib...)

CMAKE_INCLUDE_PATH:find_path will look here by default. Of course, it is better to write after PATHS.

CMAKE_LIBRARY_PATH:find_library will look here by default. Of course, it is better to write after PATHS.

Set (CMAKE_INCLUDE_PATH / usr/local/include/opencv / usr/include) find_path (CV_INCLUDE_DIRS NAMES cv.h PATHS CMAKE_INCLUDE_PATH) find_package (OpenCV REQUIRED) how to set the lookup path / specify a version # find opencv libfind_package (OpenCV REQUIRED NO_MODULE # should be optional) Tells CMake to use config mode PATHS / usr/local # look here NO_DEFAULT_PATH) # and don't look anywhere else so much about the implementation of the search path for find_package () in the C language. I hope the above content can be of some help to you and learn more knowledge. If you think the article is good, you can share it for more people to see.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report