MartinMoizard
MartinMoizard

Reputation: 6680

CMake and target_link_libraries on library depending on another lib

I am using CMake to build different C++ libraries, the whole thing can be summed up like this :

I now need to create a lib c that depends on b. Do I need to link c only on b ? or on b and a because b depends on a ?

target_link_libraries(c b) or target_link_libraries(c b a) ?

Thanks

Upvotes: 10

Views: 4907

Answers (1)

George Hilliard
George Hilliard

Reputation: 15942

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

target_link_libraries(b a)

Then, your library/application c can link to only what it uses and not have to worry about dependencies of dependencies:

target_link_libraries(c b)

Library a will be pulled in for you.

Upvotes: 14

Related Questions