problem linking a library and addressing cross dependency

classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
Report Content as Inappropriate

problem linking a library and addressing cross dependency

Zahid Iqbal

I have started using cmake recently.  I have the following question: 

For building my system, I am working with two directories. Let's call them my_application_directory and protocol_source_directory. 

The code relating to my application resides under my_application_directory.  In fact, my application needs to interact with protocol_source_directory.  My application needs some functions from  protocol_source_directory as well as it can provide some functionality to some process that is within the protocol_source_directory. 

protocol_source_directory is an existing protocol suite with its own  top-level makefile that compiles and builds the protocol and generates a static library.  The directory structure for protocol_source_directory is as follows: 

|___ dir1
        |__ config
        |__ include
        |__ libs
        |__ misc
        |__ src
                |__ modules
                |           |
                |           |__ layerA
                |           |__ layerB
                |           |__ layerC
                |           |__ layerD
                |__ debug_tests
                          |__ my_application_directory

Imagine a scenario in which there was no my_application_directory. In this case, protocol_source_directory builds and compiles with the makefile under protocol_source_directory/dir1.  The static library generated (e.g. protocol_lib.a) is available under protocol_source_directory/dir1/libs/. 

Purpose of developing an application is to add some functionality in the protocol and then develop an application to test that functionality. 

To fulfill this purpose, new files are added, 

  • Few of new files are added at the location protocol_source_directory/dir1/src/modules/layerC/. There is a local makefile at this level which is updated to reflect these new files. 
  • some of the files need some definitions from my_application_directory. Therefore, I update the local makefile to include the needed paths to my_application_directory. so that I can use necessary headers inside ".c" files without path qualifiers.

Having done this, 

protocol_source_directory builds and compiles with the makefile under protocol_source_directory/dir1 and generates the static library e.g. protocol_lib.a. 

  • Remaining functionality is implemented in files that reside under my_application_directory. It is important to note that my_application_directory can be at location protocol_source_directory/dir1/src/debug_tests/my_application_directory/ or it can exists separately at the same level as the protocol_source_directory

Imagine a scenario where, my my_application_directory is separate (not inside) the protocol_source_directory.  Here is the CMakeLists.txt that I am using to build my application while interacting with protocol source. 

cmake_minimum_required(VERSION 2.8)

# manually adding the sources using the set command as follows:
set(SRC_LIST main.c ISH.c ish_db.c ish_generator.c messages.c my_string_help.c populate_ish.c 
ISH.h ish_db.h ish_generator.h messages.h my_string_help.h populate_ish.h my_types.h)
add_executable(${PROJECT_NAME} ${SRC_LIST})

# adding c99 style options

set(FTT_BASE protocol_source_directory/dir1)

set(CORE_INCLUDES ${FTT_BASE}/src/modules/layerC/include/)
set(ETH_INCLUDES ${FTT_BASE}/src/modules/layerA/include/)
set(CORE_COMMONS ${FTT_BASE}/src/modules/layerC/common/)
set(MASTER_INCLUDES ${FTT_BASE}/src/modules/layerC/master/)

include_directories(include ${FTT_BASE}/config/ ${FTT_BASE}/misc/make-rules/ ${FTT_BASE}/misc/arch-ports/ ${CORE_INCLUDES} ${ETH_INCLUDES} ${CORE_COMMONS} ${MASTER_INCLUDES})

# linking to the protocl library code
find_library (FTT_LIB protocol_lib.a protocol_source_directory/dir1/libs/)
target_link_libraries(${PROJECT_NAME} ${FTT_LIB})

Having done all this, 

when I build my application using cmake, it gives me the following error: 

my_types.h no such file and directory

please note that my_types.h  is in my_application_directory.  But, since, some definitions are needed, I have included this file (i.e., include "my_types.h") in some .c files which are at protocol_source_directory/dir1/src/modules/layerC/.

Question:  What I am doing wrong here, I have included the needed paths to my_application_directory, in the local makefile at protocol_source_directory/dir1/src/modules/layerC/. protocol_source_directory is compiling ok, why I receive this error after I link with static project libray. 

thanks for your help and time. 




Powered by

Please keep messages on-topic and check the CMake FAQ at:

Kitware offers various services to support the CMake community. For more information on each offering, please visit:

CMake Support:
CMake Consulting:
CMake Training Courses:

Visit other Kitware open-source projects at

Follow this link to subscribe/unsubscribe: