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 8603685
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T02:22:55+00:00 2026-06-12T02:22:55+00:00

Now I am building a C++ project with CMake. I find CMake will introduce

  • 0

Now I am building a C++ project with CMake. I find CMake will introduce unnecessary library dependency in the project. Take an example, my project is composed of four parts: 1)lib1 2)lib2 3)lib3 and 4)app:

------lib1---
        |----
      lib2---
        |----
      lib3---
        |----
      app---

The source code in app will build a program, which relies on the dynamic library created in lib3. lib3 however, relies on the dynamic library created in lib2 and so on. I build the following CMake scripts to build a VC10 project:
1) Root CMakeLists:

   cmake_minimum_required( VERSION 2.6 )

    project (test)


    add_subdirectory(lib1)

    add_subdirectory(lib2)

    add_subdirectory(lib3)

    add_subdirectory(app)

2) lib1 CMakeLists.txt

add_definitions (-DEXP_STL )
add_library(lib1 SHARED lib1.cxx)

3) lib3 CMakeLists.txt

add_definitions (-DEXP_STL )
add_library(lib3 SHARED lib3.cxx)
target_link_libraries(lib3 lib2)

4) app CMakeLists.txt

add_executable(app main.cpp)
target_link_libraries(app lib3)

With these CMake scripts I have no problem in building a VC10 project. However, I notice that CMake will introduce unnecessary library dependency between libraries for VC10. For example, for the app application program, it only relies on one library, and that is, lib3. However, in VC10 project, I notice that it added the following additional dependencies:

..\lib3\Debug\lib3.lib
..\lib2\Debug\lib2.lib
..\lib1\Debug\lib1.lib

In the CMake script, however, only lib3 dependency is supposed to be introduced. For our example project, it may not be a problem, but in other cases the introduced redundant libraries can lead to compiling errors as they demand the proper searching paths. I am therefore wondering whether there is a way to eliminate these unnecessary libraries. Thanks!

  • 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-06-12T02:22:56+00:00Added an answer on June 12, 2026 at 2:22 am

    CMake adds in dependent libraries transitively, which can be turned off by setting the property LINK_INTERFACE_LIBRARIES to an empty string. If you do
    SET_TARGET_PROPERTIES(lib3 PROPERTIES LINK_INTERFACE_LIBRARIES “”)
    then CMake will not generate a dependency from app to lib1 and lib2, when linking app.

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

Sidebar

Related Questions

I am now building a dynamic library with CMake, and the problem I now
Im building some project now that I know that I will use lots of
Let's imagine I already have a project building .NET 3.5 assembly. Now I want
Right now I'm building a project management app in rails, here is some background
Right now I'm building a project management app in rails, here is some background
Right now, I'm in the middle of actually building a Project Management application, and
I am building a project using Maven. In the Pom.xml i have added dependency
I am building a windows project in .net 4.0 c#. I am now saving
We'd had a CC.NET project building for a few months now and are ready
I am building a project using Visual Studio. The project has a dependency on

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.