CMake imported target includes non-existent path

只愿长相守 提交于 2019-12-11 16:44:00

问题


I've followed the steps described in Linking against GTest fails, and get this error.

CMake Error in src/impl/data_structures/simple_tree/CMakeLists.txt:
      Imported target "GTest::GTest" includes non-existent path

        "~/local/include/"

Further messages include:

in its INTERFACE_INCLUDE_DIRECTORIES.  Possible reasons include:

  * The path was deleted, renamed, or moved to another location.

  * An install or uninstall procedure did not complete successfully.

  * The installation package was faulty and references files it does not
  provide.

EDIT: Although it loses "generality", I replaced the ~/ path with the full path, and then get this error:

/usr/bin/ld: cannot find /home/myself/local/lib/: File format not recognized

The path exists, to be sure.


回答1:


In your linked question, you are hinting to find_package() where to find GTest with a few GTEST_* variables. The library variables should provide the fully qualified name of the actual library file, not the location of the libraries. When you only provide the path, the FindGTest.cmake module uses this path as the actual library when it wraps the imported targets; this is incorrect. Try modifying your CMake to something like this, then re-run CMake from scratch:

# adding googletest
set(GOOGLETEST_PATH /home/username/local/googletest)
set(GTEST_INCLUDE_DIR /home/username/local/include/)
set(GTEST_LIBRARY /home/username/local/lib/path/to/libgtest.a)
set(GTEST_MAIN_LIBRARY /home/username/local/lib/path/to/libgtest_main.a)
find_package(GTest REQUIRED)

For what it's worth, you really shouldn't have to set all of the variables before calling find_package(). You should only need to set GTEST_ROOT as suggested in this answer.



来源:https://stackoverflow.com/questions/59010477/cmake-imported-target-includes-non-existent-path

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