“没有规则可以成为目标”将make -j与cmake一起使用时出错 [英] "No rule to make target" Error When Using make -j with cmake

查看:155
本文介绍了“没有规则可以成为目标”将make -j与cmake一起使用时出错的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我使用 make -j时,出现没有规则可以使目标的错误。当我使用make(否-j)时,我没有得到错误。该库在一个目录中按以下方式构建:

When I use "make -j" I get a "No rule to make target" error. When I use make (no -j), I don't get the error. The library is built as follows in one directory:

add_library(Environment ${CXXSRCS}

并创建libEnvironment.a,在另一个目录中引用libEnvironment.a:

and libEnvironment.a is created. In another directory libEnvironment.a is referenced:

add_executable(GetEnv ${GETSRCS})
target_link_libraries(GetEnv
    ${tools_environment_SOURCE_DIR}/libEnvironment.a
    xml++-2.6
    )

当我使用 cmake -j运行时,出现错误然后创建了库,但是cmake停止,当我再次运行cmake -j时,一切都很高兴,因为已经创建了库。有什么想法吗?

When I run with "cmake -j", I get the error then the library gets created, but cmake stops. When I run cmake -j again, everything is happy because the library has been created. Any ideas?

推荐答案

何时 make -j 正在使用,任何目标都可以并行构建,除非一个目标被显式设置为另一个目标。

When make -j is in use, any targets may be built in parallel unless one target is explicitely set as depended from another.

如果您有 GetEnv (可执行)目标,该目标使用由 Environment (库)目标,但是你h

In you case you have GetEnv (executable) target which uses files, produced by Environment (library) target. But you have no explicit dependencies between targets!

正确(最简单)的与库链接的方法是使用库目标名称而不是由该目标创建的库文件:

Correct (and the simplest) way for link with libraries is using library target name instead of library file, which is created by that target:


target_link_libraries(GetEnv Environment xml ++-2.6)

target_link_libraries(GetEnv Environment xml++-2.6)

这样,您将在 GetEnv Environment 目标之间具有依赖关系,因此 make -j 将不再尝试并行构建它们。

Such a way you will have dependency between GetEnv and Environment targets, so make -j will no longer attempt to build them in parallel.

这篇关于“没有规则可以成为目标”将make -j与cmake一起使用时出错的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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