I'm trying to set up a project where header files can be found by the subfolder libraries src code as well as the src code in the top level using Cmake. Currently i am getting an error stating that the header file can not be found. The structure of my project looks like this:
root/
src/
CMakeLists.txt #(top level)
main.c
lib/
lib1.c
CMakeLists.txt #(lower level)
headers/
lib1.h
build/
My top level CMakeLists.txt looks like this:
cmake_minimum_required(VERSION 3.13.4)
project(CmakeTUT_Proj)
add_executable(${PROJECT_NAME} main.c)
target_include_directories(${PROJECT_NAME} PUBLIC Lib/headers/)
add_subdirectory(Lib/)
target_link_directories(${PROJECT_NAME} PRIVATE Lib/headers/)
target_link_libraries(${PROJECT_NAME} name_of_lib)
My lower level CMakeLists.txt looks like:
add_library(name_of_lib adder.c)
My main.c and my lib1.c programs include the library as #include "lib1.h"
, cmake runs fine without any errors but when i build the project with make
i get an error like:
root/src/Lib/lib1.c:2:10: fatal error: lib1.h: No such file or directory
#include "lib1.h"
I want to structure my project so that main.c and lib1.c have access to lib1.h. Any ideas? Thank you.
question from:https://stackoverflow.com/questions/65559831/cmake-and-issues-with-header-files-in-subfolders