CMake导入的目标包含不存在的路径 [英] CMake imported target includes non-existent path

查看:548
本文介绍了CMake导入的目标包含不存在的路径的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经按照与GTest的链接失败中所述的步骤进行操作,并得到此错误

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/"

其他消息包括:

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.

编辑:尽管它失去了通用性,但我替换了〜/ 路径,其中
是完整路径,然后出现此错误:

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

路径确实存在。

推荐答案

在链接的问题,您是在提示 find_package()在哪里找到带有一些 GTEST _ * 变量。库变量应提供实际库文件的完全限定名称,而不是库的位置。当仅提供路径时, FindGTest.cmake 模块在包装导入的目标时将使用此路径作为实际库。这是不正确的。尝试将您的CMake修改为这样,然后从头开始重新运行CMake:

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)

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

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.

这篇关于CMake导入的目标包含不存在的路径的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆