检查包含/库路径变量(如OpenCV_LIBS)在UNIX中指向何处 [英] Check where include/library path variables like OpenCV_LIBS point to in unix
问题描述
在将OpenCV之类的库与C / C ++一起使用时,将使用OpenCV_LIBS之类的变量将编译器/链接器指向相关目录。
When using some libraries like OpenCV with C/C++, variables like OpenCV_LIBS are used to point the compiler/linker to the relevant directories.
使用 cmake :
include_directories( ${OpenCV_INCLUDE_DIRS} )
target_link_libraries( project_name ${OpenCV_LIBS} )
如何检查这些变量指向的位置?我尝试在终端中键入 set
或 printenv
,但是它只显示一些系统变量。还有如何设置/更改此类变量?
How can I check where such variables point at? I've tried typing set
or printenv
in terminal but it shows only some system variables. Also how can I set/change such variables?
推荐答案
这些变量由 cmake (请参见 OpenCVConfig.cmake
详细了解 opencv CMake变量可用)。
Those variables are determined by cmake (see OpenCVConfig.cmake
for a more detailed description of opencv CMake variables available).
要查看这些值,可以在 find_package(OpenCV)之后添加
调用项目的 message()
调用) CMakeLists.txt
:
To see those values you can add message()
calls after the find_package(OpenCV)
call to your project's CMakeLists.txt
:
find_package(OpenCV)
message(STATUS "OpenCV_INCLUDE_DIRS = ${OpenCV_INCLUDE_DIRS}")
message(STATUS "OpenCV_LIBS = ${OpenCV_LIBS}")
或者您可以运行 find_package
通过CMake命令行选项。
Alternatively you can run find_package
via a CMake command line option.
以下是一些示例(如果CMake无法找到您的库安装路径,则 CMAKE_PREFIX_PATH
部分是可选的自动):
Here are a few examples (the CMAKE_PREFIX_PATH
part is optional if CMake is not able to find your libraries installation path automatically):
-
MODE = COMPILE
给出包含目录(例如MSVC
编译器)
MODE=COMPILE
giving include directories (e.g. withMSVC
compiler)
$ cmake
--find-package
-DNAME=OpenCV
-DCOMPILER_ID=MSVC -DMSVC_VERSION=1700
-DLANGUAGE=CXX
-DMODE=COMPILE
-DCMAKE_PREFIX_PATH:PATH=/path/to/your/OpenCV/build
MODE = LINK
提供链接库(例如,使用 GNU
编译器)
MODE=LINK
giving link libraries (e.g. with GNU
compiler)
$ cmake
--find-package
-DNAME=OpenCV
-DCOMPILER_ID=GNU
-DLANGUAGE=CXX
-DMODE=LINK
-DCMAKE_PREFIX_PATH:PATH=/path/to/your/OpenCV/build
注意:此CMake调用将创建 CMakeFiles
当前工作目录中的子目录。
Note: This CMake call will create a CMakeFiles
sub-directory in your current working directory.
参考文献
- Using OpenCV with gcc and CMake
CMakeFindPackageMode
CMake module documentation
这篇关于检查包含/库路径变量(如OpenCV_LIBS)在UNIX中指向何处的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!