How / where to include?

Fredckx
Posts: 17
Joined: Mon Mar 29, 2021 8:55 pm

How / where to include?

Postby Fredckx » Mon Apr 26, 2021 9:44 am

Hi, I am pretty new to the esp-idf for VSC. I succesfully installed the extension, read the docs (Tutorials, Basic Usage) and ran several examples. Now I want to transfer an existing Arduino code (.ino) to the new environment. I created a folder and a project (took the "Hello World" example as a kind of template). I copied the code in my .ino in the hello_world_main.c file and started building.

My .ino contains several includes (.h). Not surprisingly, the builder tells me that it can not find those files. I have some questions:

1) How do I import the includes in my project? Is there a command for that?
2) Is there a way to store commonly used includes such that different projects can use them?
3) What is the best way to start a project from scratch? I see several options. Preferably I don't want to start from an example. I I have to start from a template, I want the template to be as lean/empty as possible.

Great if someone could boost my learning cycle :D
Fred

bitmandu
Posts: 6
Joined: Fri Apr 23, 2021 2:37 pm

Re: How / where to include?

Postby bitmandu » Mon Apr 26, 2021 10:46 pm

I don't use VSC, so I can't help with it specifically, but maybe this is better than nothing!

1. You can import code using the CMake build system. The file CMakeLists.txt specifies the paths for all the source and header files your project needs.

Code: Select all

idf_component_register(SRCS "hello-world.c"
                                      INCLUDE_DIRS ".")
2. The way to store commonly used code is to make "components."

3. Espressif provides a template for a new project. You can also use idf.py.

Code: Select all

idf.py create-project PROJECT_NAME
idf.py create-component COMPONENT_NAME
Good luck!

Fredckx
Posts: 17
Joined: Mon Mar 29, 2021 8:55 pm

Re: How / where to include?

Postby Fredckx » Tue Apr 27, 2021 8:45 am

@Bitmandu, thanks for your reply! I will read me into using CMake. It is also used in VS Code, so I should take care that a separate installation of CMake does not interfere with the instance in VS Code.

In the meantime I scanned the web and found vcpkg (https://docs.microsoft.com/en-us/cpp/bu ... w=msvc-160). This should be able to maintain dependencies for CMake projects as well as for VS Code projects. I tried to follow instructions for integration with VS Code, but until now without success.

Thanks again
Fred

Fredckx
Posts: 17
Joined: Mon Mar 29, 2021 8:55 pm

Re: How / where to include?

Postby Fredckx » Tue Apr 27, 2021 1:15 pm

@Bitmandu,

I have first pursued the vcpkg route. I think that I am going to abandon it. Reason: after installation I successfully installed the sqlite3 package by following the Getting started. That went OK and I was able to detect that the package was present by vcpkg list. This was all still outside the VS Code environment. As a next step I tried to find Wire.h, just as it is code that is commonly used in my projects. ./vcpkg search Wire.h did not give results, so I am afraid that common packages like this are not accessible via this tool.

I now plan to try:

- installing e.g. Wire.h directly in my project folder's include folder. The disadvantage is that I have to do it again for every project. This can be time consuming when I have many includes that also may have nested dependencies,

- therefore I want to try if in the c_cpp_properties.json I can add a pointer at the location where my Arduino IDE stores the header files. I could then use the Arduino IDE to install new packages (and automatically their dependencies).

Who is online

Users browsing this forum: Baidu [Spider] and 89 guests