# Build error as header file not found

**URL:** <https://discourse.cmake.org/t/build-error-as-header-file-not-found/15357>\
**Category:** Code\
**Created:** [December 2, 2025, 11:44am UTC](https://discourse.cmake.org/t/build-error-as-header-file-not-found/15357 "2025-12-02T11:44:35Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Maaz\_Madha](https://discourse.cmake.org/user_avatar/discourse.cmake.org/maaz_madha/32/5927_2.png) [@Maaz\_Madha](https://discourse.cmake.org/u/Maaz_Madha)\
**Post date:** [December 2, 2025, 11:44am UTC](https://discourse.cmake.org/t/build-error-as-header-file-not-found/15357/1 "2025-12-02T11:44:35Z")

</div>

Hi all

I hve a C project for raspberry pico and I’m trying to organise it properly so it looks legible and decent. I am using the tinyusb library and one of the main ones that is important is tusb\_config.h, and after reformatting and cleaning up my code enough I get this error

path/src/tusb\_option.h:257:12: fatal error: tusb\_config.h: No such file or directory  
257 | #include “tusb\_config.h”  
| ^ ~~~~~~~~~~~~~~

1. Below is the app main source file which uses tusb\_config.h and I have included the error using file sets, as recommended in ProfessionalCMake. However, it still isn’t working

```auto
add_executable(app_main main.c)

target_sources(app_main
   PUBLIC
    FILE_SET HEADERS
    BASE_DIRS
        ${CMAKE_SOURCE_DIR}/src
        ${CMAKE_SOURCE_DIR}/file_processing
        ${CMAKE_CURRENT_SOURCE_DIR})

## target_include_directories(app_main PRIVATE ${CMAKE_CURRENT_SOURCE_DIR} PUBLIC ${CMAKE_SOURCE_DIR}/src ${CMAKE_SOURCE_DIR}/file_processing)
target_link_libraries(app_main PUBLIC file_processing host_storage fatfs_csv)

pico_add_extra_outputs(app_main)

```

1. Below is the subdirectory which includes the tusb\_config.h. Also as a side question, do I have to include header files into the add\_library command, or can it be only .c files.

```auto
set(FATFS_LIB_SOURCES 

 $ENV{PICO_TINYUSB_PATH}/lib/fatfs/source/ff.c 

 $ENV{PICO_TINYUSB_PATH}/lib/fatfs/source/ffsystem.c 

 $ENV{PICO_TINYUSB_PATH}/lib/fatfs/source/ffunicode.c)

set(FATFS_LIB_HEADERS

    $ENV{PICO_TINYUSB_PATH}/lib/fatfs/source

)

set(SRC_SOURCES

    msc_app.c

    )

set(SRC_HEADERS

    msc_app.h

    tusb_config.h

    embedded_cli.h)

add_library(host_storage STATIC

         ${SRC_SOURCES} ${SRC_HEADERS} ${FATFS_LIB_SOURCES} ${FATFS_LIB_HEADERS}  

        )

target_sources(host_storage 

    PUBLIC

        FILE_SET HEADERS 

        BASE_DIRS

            ${FATFS_LIB_HEADERS}

            ${CMAKE_CURRENT_SOURCE_DIR}

)        

# target_include_directories(host_storage

# PUBLIC

# ${CMAKE_CURRENT_SOURCE_DIR}

# ${FATFS_LIB_HEADERS}

# )

target_link_libraries(host_storage

    PUBLIC

        tinyusb_host

        tinyusb_board

        pico_stdlib

)

```

Any help or advice would be much appreciated

Kind regards

---

<div class="post-metadata">

**Author:** ![AnthonyD973](https://discourse.cmake.org/user_avatar/discourse.cmake.org/anthonyd973/32/3130_2.png) [@AnthonyD973](https://discourse.cmake.org/u/AnthonyD973)\
**Post date:** [December 3, 2025, 10:12pm UTC](https://discourse.cmake.org/t/build-error-as-header-file-not-found/15357/2 "2025-12-03T22:12:41Z")

</div>

> [@Maaz\_Madha](#):
>
> ```auto
> target_sources(app_main
> PUBLIC
> FILE_SET HEADERS
> BASE_DIRS
> ${CMAKE_SOURCE_DIR}/src
> ${CMAKE_SOURCE_DIR}/file_processing
> ${CMAKE_CURRENT_SOURCE_DIR})
> 
> ```

That would explain the error with the `#include`. You need to specify the header files:

```auto
target_sources(app_main
   PUBLIC
    FILE_SET HEADERS
    BASE_DIRS
        ${CMAKE_SOURCE_DIR}/src
        ${CMAKE_SOURCE_DIR}/file_processing
        ${CMAKE_CURRENT_SOURCE_DIR}
    # Or just manually list the headers here directly instead of
    # expanding "${SRC_HEADERS}"
    FILES ${SRC_HEADERS})

```

`target_sources` will complain if for any reason the headers in question aren’t within one within one of the BASE\_DIRS you’ve specified. That is intentional and desirable; either move your headers within one of the BASE\_DIRS or change your BASE\_DIRS.

> [@Maaz\_Madha](#):
>
> Below is the subdirectory which includes the tusb\_config.h. Also as a side question, do I have to include header files into the add\_library command, or can it be only .c files.

Only the .c/.cpp files are usually needed. For the headers, all you need is to make sure the headers are available when building the library and when some other target (e.g. `app_main`) uses that library. As long as you’re using `target_sources(your_library ...)` and `target_link_libraries(app_main PUBLIC/PRIVATE/INTERFACE <libraries...>)` everywhere, you should be okay.
