Page 1 of 1

Main file cannot view includes in another file

Posted: Mon Nov 04, 2024 11:20 pm
by yanmartins
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?

Re: Main file cannot view includes in another file

Posted: Tue Nov 05, 2024 7:12 am
by ESP_Sprite
Potentially the issue is that you don't have any C files to compile.

Re: Main file cannot view includes in another file

Posted: Tue Nov 05, 2024 9:27 am
by yanmartins
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.

Re: Main file cannot view includes in another file

Posted: Tue Nov 05, 2024 11:38 am
by chegewara
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

Re: Main file cannot view includes in another file

Posted: Wed Nov 06, 2024 11:39 pm
by yanmartins
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