Check where include/library path variables like OpenCV_LIBS point to in unix

╄→гoц情女王★ 提交于 2020-07-17 10:22:22

问题


When using some libraries like OpenCV with C/C++, variables like OpenCV_LIBS are used to point the compiler/linker to the relevant directories.

Examples using cmake:

include_directories( ${OpenCV_INCLUDE_DIRS} )
target_link_libraries( project_name ${OpenCV_LIBS} )

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?


回答1:


Those variables are determined by cmake (see OpenCVConfig.cmake for a more detailed description of opencv CMake variables available).

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}")

Alternatively you can run find_package via a CMake command line option.

Here are a few examples (the CMAKE_PREFIX_PATH part is optional if CMake is not able to find your libraries installation path automatically):

  1. MODE=COMPILE giving include directories (e.g. with MSVC 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
    
  2. 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
    

Note: This CMake call will create a CMakeFiles sub-directory in your current working directory.


References

  • Using OpenCV with gcc and CMake
  • CMakeFindPackageMode CMake module documentation


来源:https://stackoverflow.com/questions/33981618/check-where-include-library-path-variables-like-opencv-libs-point-to-in-unix

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!