Main file cannot view includes in another file

yanmartins
Posts: 5
Joined: Tue Mar 14, 2023 4:03 pm

Main file cannot view includes in another file

Postby yanmartins » Mon Nov 04, 2024 11:20 pm

Hello,

I have a project with the following organization:

.
├── CMakeLists.txt
├── app
│ ├── inc
│ │ └── app_default.h
│ ├── src
│ │ └── dummy.c
│ └── CMakeLists.txt
├── main
│ ├── CMakeLists.txt
│ └── main.c
└── srv
├── inc
└── src

Root CMakelists.xtx:

Code: Select all

# The following lines of boilerplate have to be in your project's
# CMakeLists in this exact order for cmake to work correctly
cmake_minimum_required(VERSION 3.16)

include($ENV{IDF_PATH}/tools/cmake/project.cmake)
project(bme280_i2c)
Main folder CMakeLists.txt:

Code: Select all

set(srcs "main.c")

idf_component_register(SRCS ${srcs}
    INCLUDE_DIRS "."
    PRIV_REQUIRES app srv)
App folder CMakeLists.txt:

Code: Select all

idf_component_register(
    INCLUDE_DIRS "inc"
)
But I get the following error:

C:/Users/Yan/Documents/GitHub/univali-iot-node-sensor/main/main.c:34:10: fatal error: app_default.h: No such file or directory
#include "app_default.h"
^~~~~~~~~~~~~~~
compilation terminated.
make[1]: *** [/c/Espressif/ESP8266_RTOS_SDK/make/component_wrapper.mk:292: main.o] Error 1
make: *** [C:\Espressif\ESP8266_RTOS_SDK/make/project.mk:571: component-main-build] Error 2
make: *** Waiting for unfinished jobs....

What could I be doing wrong?

ESP_Sprite
Posts: 9757
Joined: Thu Nov 26, 2015 4:08 am

Re: Main file cannot view includes in another file

Postby ESP_Sprite » Tue Nov 05, 2024 7:12 am

Potentially the issue is that you don't have any C files to compile.

yanmartins
Posts: 5
Joined: Tue Mar 14, 2023 4:03 pm

Re: Main file cannot view includes in another file

Postby yanmartins » Tue Nov 05, 2024 9:27 am

Hello,

I included the app_default file inside my main.c. Why wouldn't this work?

The main.c file contains code. If I make the glasses like: #include "../app/inc/app_default.h" it works.

But I want to add the file to cmakelist to make the include cleaner.

chegewara
Posts: 2375
Joined: Wed Jun 14, 2017 9:00 pm

Re: Main file cannot view includes in another file

Postby chegewara » Tue Nov 05, 2024 11:38 am

How about this

Code: Select all

set(srcs "main.c")

idf_component_register(SRCS ${srcs}
    INCLUDE_DIRS "." "./app/inc"
    PRIV_REQUIRES app srv)
CMakeLists.txt in app folder is ignored, because app is just a subfolder not actual component.

When you add this change in the main CMakeLists.txt you will end up with another build problem, because source files from app are not included, so it is better to move app folder to new components subfolder, like most of us do, or to add in project CMakeLists.txt file directive that will use app folder as extra components.

This is very good source of information
https://www.youtube.com/watch?v=7utLBxSOXlQ

yanmartins
Posts: 5
Joined: Tue Mar 14, 2023 4:03 pm

Re: Main file cannot view includes in another file

Postby yanmartins » Wed Nov 06, 2024 11:39 pm

I tried adding it inside a components folder and putting any .c inside the app folder. But I still get the same error.

I watched the video sent, tested what was informed but was also unsuccessful. Could I be missing something?

This is my repository:

https://github.com/yanmartins/univali-i ... older_arch

Who is online

Users browsing this forum: No registered users and 7 guests