Doug Fulford
Doug Fulford

Reputation: 59

"No rule to make target" Error When Using make -j with 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?

Upvotes: 1

Views: 1358

Answers (1)

Tsyvarev
Tsyvarev

Reputation: 65870

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

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)

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

Upvotes: 3

Related Questions