Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6472333
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T06:19:54+00:00 2026-05-25T06:19:54+00:00

Say I have a target A that depends on the libraries B and C

  • 0

Say I have a target A that depends on the libraries B and C. But B and C have no mutual dependence. The linking with CMake could look like

target_link_libraries( A B C )

but

target_link_libraries( A B )
target_link_libraries( A C )

also seems to work (and might be more easy to maintain). Are there disadvantages of splitting the target_link_libraries command into multiple commands? Or should one always put it into a single command in case one eventually does encounter a mutual dependence of the libraries?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-25T06:19:54+00:00Added an answer on May 25, 2026 at 6:19 am

    Those are exactly equivalent. Both say that A depends on B and A depends on C. Neither says anything about any dependency between B and C, so there is none.

    I’m not sure what you mean by “mutual dependence” — when considering B and C, there are 4 possibilities: (1) neither depends on the other, (2) B depends on C, (3) C depends on B, or (4) they both depend on each other.

    (1) is what you have. (2) and (3) would mean you should add another target_link_libraries command with either “B C” as the args or “C B” respectively. (4) means you have a circular dependency and they really shouldn’t be separate libraries at all, but combined into a single logical entity. You should avoid (4) because it makes it impossible to load as shared libraries on some (all?) platforms.

    There is negligible performance penalty for having two separate target_link_libraries calls. I doubt you could measure the performance and show any significant timing differences.

    To clarify, this call:

    target_link_libraries(A B C)
    

    means target A requires libraries B and C.

    If, instead, you consider case (2) above, where B depends on C, you would instead write:

    target_link_libraries(B C)
    target_link_libraries(A B)
    

    which means target B requires library C, and target A requires library B (and CMake automatically transitively propagates B’s dependencies to A so that you do not have to know about any A -> C dependence unless you have explicit code that calls functionality in library C).

    You should always express the minimum dependency information necessary to link things together.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have defined a custom target in cmake. I now want to ensure that
Let's say I have a main target, exe which depends on three libs: exe:
Let's say I have a web site for hosting community generated content that targets
Say I have an input file, and a target directory. How do I determine
lets say we have a link <a href=/something target=_new>blah</a> and now i want a
Let's say have something like: SELECT energy_produced, energy_consumed, timestamp1 AS timestamp FROM ( SELECT
Let's say I have a table that has a varchar field. If I do
Is there any way to say that if prerequisite for the given target doesn't
say I have input data like so: firstName | lastName | Country Bob |
Lets say I have a class like this: Class User { var $id var

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.