ESP-IDF include additional paths

ThomasB
Posts: 38
Joined: Sun Dec 25, 2016 12:11 am

ESP-IDF include additional paths

Postby ThomasB » Thu Jan 12, 2017 9:27 pm

Hi,

my first ESP32 project develops and of course I want to organize the headers and sources in a structured way.

However, if I create a new folder in the workspace and add it as include path(eclipse), the make process cant find it.

I use the latest version (cloned today) of ESP-IDF on windows with eclipse.
My naive approach was to add the include path inside of eclipse, but I am afraid this information is not passed to make.

Could someone please give instruction on how to add additional header/source folders.

Sorry if this is a duplicate post, I could not find any information about it in the forum or online. (Mainly because the keywords are used very often...) :|

User avatar
kolban
Posts: 1683
Joined: Mon Nov 16, 2015 4:43 pm
Location: Texas, USA

Re: ESP-IDF include additional paths

Postby kolban » Thu Jan 12, 2017 10:42 pm

Howdy,
Here is a video called "ESP32: Integration with Eclipse"....

https://www.youtube.com/watch?v=bYh2w0HzS7s

Have a look at this and see if it answers the question. It it doesn't please post back.

From a high level ... the way I think about it ...

The ESP-IDF make system uses "component.mk" files to specify which directories each component provides (if any) include files.
The Eclipse environment "drives" the Makefile provided with ESP-IDF and hence doesn't "actually" have to know where the include files reside in order for a build to complete successfully. However, for entry assist and for the Eclipse editors, we can go further and "tell" the Eclipse project which folders to search for include files ... for the purpose of clean editing.
Free book on ESP32 available here: https://leanpub.com/kolban-ESP32

ESP_Angus
Posts: 2344
Joined: Sun May 08, 2016 4:11 am

Re: ESP-IDF include additional paths

Postby ESP_Angus » Fri Jan 13, 2017 5:12 am

In addition to kolban's answer, you can find the documentation of "component.mk" contents here:

EDIT: updated the link to the new location
https://docs.espressif.com/projects/esp ... -variables

You can use either COMPONENT_ADD_INCLUDEDIRS or COMPONENT_PRIV_INCLUDEDIRS (depending if the headers are "public" or "private") to tell the esp-idf 'make' system where to find headers.

Angus

ThomasB
Posts: 38
Joined: Sun Dec 25, 2016 12:11 am

Re: ESP-IDF include additional paths

Postby ThomasB » Fri Jan 13, 2017 9:59 am

Hi,

COMPONENT_ADD_INCLUDEDIRS and COMPONENT_SRCDIRS work fine.

Thanks!

kolban, you are right. Eclipse is simply a convenient editor, which has to know the include paths in order to ease editing. However, from GCC I know that additional eclipse include dirs are passed in the CLI. I thought that the make script maybe is getting this information too. But to be honest, I do not know very much about make ;)

MarcLM
Posts: 1
Joined: Tue Aug 08, 2017 7:25 am

Re: ESP-IDF include additional paths

Postby MarcLM » Tue Aug 08, 2017 7:32 am

Hello,

I have a question with the project organization that i want to resolve. I want to organize my project with another name folders. Could someone say how to change the name of the main folder? I have this folders:
- .git
- build
- main (i want to name it src)

thx

User avatar
kolban
Posts: 1683
Joined: Mon Nov 16, 2015 4:43 pm
Location: Texas, USA

Re: ESP-IDF include additional paths

Postby kolban » Tue Aug 08, 2017 1:58 pm

Howdy,
In your ESP-IDF project you will find a Makefile. This is in the same folder as "main".

You can name the sub directories that are going to contain source to be compiled by adding the variable SRCDIRS into the Makefile. If you don't supply it, the implicit default is "main".

For example, you can add the following:

SRCDIRS := src

which will result in the application being compiled with the content of a directory called "src" rather than main.
Free book on ESP32 available here: https://leanpub.com/kolban-ESP32

gregstewart90
Posts: 59
Joined: Thu Jan 19, 2017 5:17 pm

Re: ESP-IDF include additional paths

Postby gregstewart90 » Tue Aug 15, 2017 7:59 pm

I've been able to organize my project with multiple directories in the 'main' directory. I would like to add subdirectories to some of those directories.

Code: Select all

->main
    ->dir_1
    ->dir_2
    ->dir_3
        ->dir_3_a
        ->dir_3_b
            ->dir_3_b_1
In my main directory, I have a component.mk file with the following:
COMPONENT_SRCDIRS := . dir_1 dir_2 dir_3

If I try adding dir_3/dir_3_a, I get the following error:

Code: Select all

 /path/to/project/main/dir_3/dir_3_a/file.c fatal error: opening dependency file dir_3/dir_3_a/file.d: No such file or directory

snahmad75
Posts: 445
Joined: Wed Jan 24, 2018 6:32 pm

Re: ESP-IDF include additional paths

Postby snahmad75 » Sun Mar 11, 2018 1:16 pm

Hi,

I am using mingw on windows 10 installed under : c:\msys32

My project is under different folder.

c:\Work. It refer to my own libraries path.

COMPONENT_ADD_INCLUDEDIRS = ../LibDev/

works instead of
COMPONENT_EXTRA_INCLUDES := ../LibDev/

c:Work\LibDev\test.h

but linker not finding method to link with test.cpp


Thanks,
Naeem

User avatar
kolban
Posts: 1683
Joined: Mon Nov 16, 2015 4:43 pm
Location: Texas, USA

Re: ESP-IDF include additional paths

Postby kolban » Sun Mar 11, 2018 5:31 pm

We might need some more information from you to assist. Include directories are where the compiler looks for header files (.h files) that contain declarations of data and functions. These are used during compilation. At the conclusion of compilation you have object files and libraries. These then are linked together to form your application.

This thread talks about how the compiled looks for header files to compile source code. At the end of your last post, you mentioned there was a problem with "linking" and not with "compilation". The include paths (for headers) aren't related to the linkage steps. Perhaps if you describes your thought process and what you are actually observing we could provide better guidance?
Free book on ESP32 available here: https://leanpub.com/kolban-ESP32

snahmad75
Posts: 445
Joined: Wed Jan 24, 2018 6:32 pm

Re: ESP-IDF include additional paths

Postby snahmad75 » Sun Mar 11, 2018 9:49 pm

Hi,

Yes you are right. My issue is now linking with my own static library.

My project is under this folder.
C:\Work\Actisense\http_server2
C:\Work\Actisense\http_server2\main\component.mk
content
COMPONENT_ADD_LDFLAGS=-lstdc++ -l$(COMPONENT_NAME)
COMPONENT_ADD_INCLUDEDIRS := . ../../../LibDev/

I can compile it but not linking to static lib ray contains test.cpp

but when I It include test.h
C:\Work\LibDev\CommonLib\test.h
C:\Work\LibDev\CommonLib\test.cpp
C:\Work\LibDev\CommonLib\component.mk

Content of file=component.mk are
#CXXFLAGS+=-fexceptions
#CXXFLAGS+= -std=c++11

COMPONENT_ADD_INCLUDEDIRS := CommonLib
COMPONENT_SRCDIRS := CommonLib
COMPONENT_SUBMODULES := CommonLib



IDF_PATH = C:/msys32/home/naeem/esp/esp-idf

Current Mingw installation folder.
C:\msys32

Error:

LD build/app-template.elf
C:/Work/Actisense/http_server2/build/main\libmain.a(main.o):(.literal.app_main+0x18): undefined reference to `test::execute()'
C:/Work/Actisense/http_server2/build/main\libmain.a(main.o): In function `app_main':
C:/work/Actisense/http_server2/main/main.cpp:95: undefined reference to `test::execute()'
collect2.exe: error: ld returned 1 exit status
make: *** [C:/msys32/home/naeem/esp/esp-idf/make/project.mk:389: /c/Work/Actisense/http_server2/build/app-template.elf] Error 1

It is not generating libCommonLib.a file

Kindly help me please.

However If i put CommonLib under C:\msys32\home\naeem\esp\esp-idf\components it links. it generate libCommonLib.a file.
Last edited by snahmad75 on Mon Mar 12, 2018 4:53 pm, edited 2 times in total.

Who is online

Users browsing this forum: No registered users and 56 guests