CMake导入的目标包含不存在的路径

问题描述 投票:0回答:1

我已按照Linking against GTest fails中所述的步骤进行操作,并出现此错误。

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

        "~/local/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.

编辑:尽管它失去了“通用性”,但我将~/路径替换为完整路径,然后出现此错误:

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

确定路径存在。

cmake googletest
1个回答
1
投票

在链接的question中,您提示find_package()在哪里可以找到带有几个GTEST_*变量的GTest。库变量应提供实际库文件的完全限定名称,而不是库的location。当仅提供路径时,FindGTest.cmake模块在包装导入的目标时将其用作实际库。这是不正确的。尝试将您的CMake修改为类似这样的内容,然后从头开始重新运行CMake:

# 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)

对于它的价值,在调用find_package()之前,您实际上不必设置所有变量。您只需要按照GTEST_ROOT答案中的建议设置this

© www.soinside.com 2019 - 2024. All rights reserved.