CMake and target_link_libraries in the library depending on another library

I use CMake to create different C ++ libraries, all this can be summarized as follows:

  • lib a: nothing depends
  • lib b: depends on

Now I need to create lib c, which depends on b. Do I need to bind c to b only? or on b and a because b depends on?

target_link_libraries (cb) or target_link_libraries (cba)?

thank

+4
source share
1 answer

In your code building library b, you must tell CMake that b depends on:

target_link_libraries(b a)

Then, your library / application c can only reference what it uses, and there is no need to worry about dependency dependencies:

target_link_libraries(c b)

Library a will be delivered to you.

+7

All Articles