CMake cannot resolve runtime directory path

After running cmake CMakeLists.txt

I get the following warning

CMake Warning at src/CMakeLists.txt:32 (add_executable):
  Cannot generate a safe runtime search path for target MMPEditor because
  files in some directories may conflict with libraries in implicit
  directories:

runtime library [libQt5Widgets.so.5] in /usr/lib/x86_64-linux-gnu may be hidden by files in:
  /home/ch/Qt/5.2.1/gcc_64/lib
runtime library [libQt5Core.so.5] in /usr/lib/x86_64-linux-gnu may be hidden by files in:
  /home/ch/Qt/5.2.1/gcc_64/lib
runtime library [libQt5Gui.so.5] in /usr/lib/x86_64-linux-gnu may be hidden by files in:
  /home/ch/Qt/5.2.1/gcc_64/lib
runtime library [libQt5OpenGL.so.5] in /usr/lib/x86_64-linux-gnu may be hidden by files in:
  /home/ch/Qt/5.2.1/gcc_64/lib

Some of these libraries may not be found correctly.

What does it mean for one file to be hidden by another and how can I allow CMake to determine which is the right folder to link to?


Your system libraries are conflicting with your local custom build Qt libraries. Its a warning but you might not get expected results in your application because of this. You need to tell CMake that it should exclude system path while searching for libraries in your CMakeModule. From this documentation

If NO_DEFAULT_PATH is specified, then no additional paths are added to the search.

Also in same documentation one more flag is mentioned NO_CMAKE_SYSTEM_PATH which only include platform specific default paths.


If you're dealing with find_library

find_library(LIBRARY_NAME PATHS "/usr/lib/x86_64-linux-gnu" NO_DEFAULT_PATH) where

  • PATHS stands for the exact path to the libs
  • NO_DEFAULT_PATH means, that cmake will not search anywhere else
  • check the values of lib and include paths with message(status, ${LIBRARY_NAME})


    If you're dealing with find_package :

    It's a bit more complicated than the previous example, but it's essentially the same.

    For each package you have to run find_package for:

  • Create file with name Find<Packagename>.cmake , eg if you're looking for cppunit, you'll have to create FindCPPUNIT.cmake .

  • In that file, you'll have to run find_path on include files and find_library on lib files, like in "If you're dealing with find_library ".

    find_path(CPPUNIT_INCLUDE_DIR PATHS "/usr/include/x86_64-linux-gnu" NO_DEFAULT_PATH)       
    find_library(CPPUNIT_LIBRARY PATHS "/usr/lib/x86_64-linux-gnu" NO_DEFAULT_PATH)
    

    And then you have to add the path to the file to CMAKE_MODULE_PATH .

  • 链接地址: http://www.djcxy.com/p/78256.html

    上一篇: 懒惰,为什么要在Django中使用它们?

    下一篇: CMake无法解析运行时目录路径