"No rule to make target" Error When Using make -j with cmake

时间:2016-03-04 17:50:11

标签: c++ cmake

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}

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
    )

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?

1 个答案:

答案 0 :(得分:1)

make -j正在使用时,除非一个目标明确设置为依赖另一个目标,否则任何目标都可以并行构建。

在您的情况下,您拥有GetEnv(可执行)目标,该目标使用由Environment(库)目标生成的文件。但是目标之间没有明确的依赖关系!

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

  

target_link_libraries(GetEnv 环境 xml ++ - 2.6)

这样一来,您就会在GetEnvEnvironment目标之间产生依赖关系,因此make -j将不再尝试并行构建它们。