0

Lets say that we have a directory which also has two libraries inside like :

/Example
   -/libA:
       CMakeLists.txt
       source1.c
   -/libB:
       source2.c
       source2.h

Is there any way, without having an external CMakeLists.txt file from libA and libB, to exists access from the source1.c file in libA in source2 files from libB?
All am I need is if i could with some way build the CMakeLists.txt in libA with a way in order, when I build my project not showing the error, cant find files from libB.

I was trying this but it faild.

 add_library(libA STATIC source1.c)
 add_library(libB STATIC source2.c source2.h)
 target_link_libraries(libA PUBLIC libB)
gregni
  • 417
  • 3
  • 12
  • So you need to specify *include directories*. In CMake that could be achieved with `target_include_directories` (preferred) or `include_directories` commands. – Tsyvarev Jul 28 '21 at 11:41
  • @Tsyvarev Can you provide a small example with the items above ? – gregni Jul 28 '21 at 12:30
  • Something like `include_directories("${CMAKE_CURRENT_SOURCE_DIR}/../libB")`. – Tsyvarev Jul 28 '21 at 13:21
  • 1
    In a `CMakeLists.txt` file paths are relative to the directory containing the `CMakeLists.txt` file. Since source1.c and source2.c are located in different directories the paths cannot work as presented... I strongly recommend creating seperate `CMakeLists.txt` files for both libs, but assuming you for some reason cannot do this, you'll need to get the paths correct. Probably you'll also need to do something about the include directories to make source2.h available in libA – fabian Jul 28 '21 at 17:16

0 Answers0