Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

CMake rejects a second target_link_libraries talking about "keyword" vs "plain" [duplicate]

I'm compiling a binary, and I want to add its dependency libraries in two different target_link_libraries() commands for various reasons.

My commands look like this:

target_link_libraries(my_prog PRIVATE foo bar)
target_link_libraries(my_prog baz)

and I get the error:

  The keyword signature for target_link_libraries has already been used with
  the target "my_prog".  All uses of target_link_libraries with a target
  must be either all-keyword or all-plain.

  The uses of the keyword signature are here:

   * tests/CMakeLists.txt:10 (target_link_libraries)

What does this mean? What should I do?

like image 891
einpoklum Avatar asked Dec 29 '19 18:12

einpoklum


1 Answers

Your use of target_link_libraries() is indeed problematic, as it involves two different "flavors" of this command, a traditional and a newer one.

In one use, you specify the dependency is PRIVATE; in the other, you specify nothing. That's not acceptable: Either you specify PUBLIC/PRIVATE/INTERFACE for all elements, or for none.

So, you can fix your CMakeLists.txt to say either:

target_link_libraries(my_prog foo bar)
target_link_libraries(my_prog baz)

or

target_link_libraries(my_prog PRIVATE foo bar)
target_link_libraries(my_prog PRIVATE baz)
like image 169
einpoklum Avatar answered Nov 20 '22 16:11

einpoklum