# specifying dependency between two third-party libraries

**URL:** <https://discourse.cmake.org/t/specifying-dependency-between-two-third-party-libraries/13620>\
**Category:** Code\
**Created:** [February 22, 2025, 6:56pm UTC](https://discourse.cmake.org/t/specifying-dependency-between-two-third-party-libraries/13620 "2025-02-22T18:56:42Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![Roberto\_Putzu](https://discourse.cmake.org/user_avatar/discourse.cmake.org/roberto_putzu/32/5363_2.png) [@Roberto\_Putzu](https://discourse.cmake.org/u/Roberto_Putzu)\
**Post date:** [February 22, 2025, 6:56pm UTC](https://discourse.cmake.org/t/specifying-dependency-between-two-third-party-libraries/13620/1 "2025-02-22T18:56:42Z")

</div>

Dear All,

I’ve starting using cmake only a couple of days ago to upgrade the build system (Makefiles pretty much) of my Fortran projects.

I’ve run into the problem described below and apparently it has not been treated before in this forum…

LIB\_A is an already compiled, static library written in C.  
LIB\_B is an already compiled, static library written in Fortran. It is the interface to LIB\_A.  
LIB\_C is an already compiled, static library written in Fortran.

LIB\_D is the library I’m trying to build in this project.  
LIB\_D needs LIB\_B and LIB\_C.

Since the project uses the interface LIB\_B, it does not need the header files .h of LIB\_A.  
How do I specify that, at linking time, that **ld** needs to link the test program to libLIB\_A.a ?

It also should be done in a particular order since LIB\_B depends on LIB\_A.

The CMakeLists.txt file below fails to build if I run “cmake --build build”.

Would you be so kind to help me?  
Thank you so much

```auto
cmake_minimum_required(VERSION 3.1)

project(P44 VERSION 1.0
        DESCRIPTION "LIB_D: A library to do this and that"
        LANGUAGES Fortran)
enable_language(Fortran)

add_library(LIB_A UNKNOWN IMPORTED)
find_library(LIB_A NAMES lib_a HINTS path_a)
add_library(LIB_B UNKNOWN IMPORTED)
find_library(LIB_B NAMES lib_b HINTS path_b)
add_library(LIB_C UNKNOWN IMPORTED)
find_library(LIB_C NAMES lib_c HINTS path_c)
add_dependencies(LIB_B LIB_A)

set(SRC_DIR src)

set(SRC_FILES 
${SRC_DIR}/lib_d_file1.f90
${SRC_DIR}/lib_d_file2.f90
)

set( CMAKE_Fortran_MODULE_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/modules)

add_library(LIB_D STATIC ${SRC_FILES} )
target_include_directories(LIB_D PUBLIC path_b/modules)
target_include_directories(LIB_D PUBLIC path_c/modules)
target_link_libraries(LIB_D ${LIB_B})
target_link_libraries(LIB_D ${LIB_C})

add_executable(test_lib_d_program test/test_lib_d.f90)
target_link_libraries(test11 LIB_D) 

install(DIRECTORY ${CMAKE_Fortran_MODULE_DIRECTORY} DESTINATION ${CMAKE_INSTALL_PREFIX})

install(TARGETS LIB_D DESTINATION ${CMAKE_INSTALL_PREFIX}/lib)

```
